If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Awkward MySQL select query...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-06, 06:47
kaddyuk kaddyuk is offline
Registered User
 
Join Date: Oct 2004
Posts: 2
Awkward MySQL select query...

OKay I have delivery_tb

Delivery ID - Int(6) - Primary Key - Auto Increment
UserID - Int(6)
CarID - Int(6)
ManufacturerID - Int(6)
Date - Timestamp
Delivered - Enum(0,1)

I need to to select a maximum of 20 rows per Unique ManufacturerID...
I need to also select a maximum of 5 rows per Unique UserID per Unique ManufacturerID...

So that no user can get more than 5 cars delivered per manufacturer per month...

I'm using PHP5 as well...
Reply With Quote
  #2 (permalink)  
Old 01-26-06, 06:56
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
the group by & having clauses would be worth a look
also the "top" sub clause eg "select top n from"

dependiogn on what version of MySQL you are using you could enforce the no more than 5 cars a month rule using a teble level constraint

does the coursework have to a PHP solution, a MySQL solution or a combined / overall solution?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 01-26-06, 07:18
kaddyuk kaddyuk is offline
Registered User
 
Join Date: Oct 2004
Posts: 2
If I can get this to be an all-in-one query (i.e. not having to loop through PHP and perform multiple queries) then that is the ideal solution...

I'll have a look through what you have suggested...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On