Jump to content

[SOLVED] Interesting Query idea


SirChick

Recommended Posts

I was wondering if this can be done with a query.. lets say we have a table with a field called name.

 

So the list is:

 

Cheese

Bacon

Cheese

Cheese

Sausage

Bacon

Bacon

 

Now im trying to see if you can make a query so that the query will find only the name field where by there is less than 3 records with that name....

 

So in this particular situation if the query is possible only Sausage should appear:

 

1.Cheese

1.Bacon

2.Cheese

3.Cheese

1.Sausage

2.Bacon

3.Bacon

 

Can that be done =/ ive not made a query this complex before so worth asking first..cos I got no idea..

Link to comment
Share on other sites

I gave it a try dont think i got it right lol

 

$CountNames = ("SELECT *, count(BusinessType) as C FROM `businesses` GROUP BY BusinessType HAVING C < 3");
$findbusinessresult = @mysql_query($CountNames) or die(mysql_error());

Echo $findbusinessresult;

 

No echo happens though =/

 

Just so you know on this the object is to find only the business types where by there are only 2 or less currently owned.

 

So if there was 3 hardware shops .. in the table.. that would suggest there are 3 already owned and so it would not show the field "businesstype" for that business.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.