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 > nested sql query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-17-07, 15:27
dannydd dannydd is offline
Registered User
 
Join Date: Sep 2007
Posts: 3
nested sql query

select a.clientname, c.catlabel
from clientsegueads a product_adcategories b product_categories c
WHERE b.catid
IN (select c.catid from product_categories where c.cadid = "493")
LIMIT 3;

clientsegueads
----------------------
cadid
clientname

product_adcategories (bridge table)
--------------------------------
cadid
cat_id

product_categories
----------------------------
cat_id
cat_label

any clues what im donig wrong ?
Reply With Quote
  #2 (permalink)  
Old 09-17-07, 16:12
dannydd dannydd is offline
Registered User
 
Join Date: Sep 2007
Posts: 3
im trying to select 3 random products from clientsegueads from the same category such as Health.
Reply With Quote
  #3 (permalink)  
Old 09-17-07, 17:07
dannydd dannydd is offline
Registered User
 
Join Date: Sep 2007
Posts: 3
I tried this .. doesnt work .. not sure ???

SELECT a.clientname
FROM clientsegueads a LEFT JOIN product_adcategories b ON a.cadid = b.cadid
LEFT JOIN product_categories c ON ( b.catid = c.catid
AND b.cadid = "342" )
WHERE a.disabled = 'N'
AND stopdate > NOW( )
AND b.cadid <> "342"
ORDER BY RAND( )
LIMIT 3
Reply With Quote
  #4 (permalink)  
Old 09-18-07, 07:08
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Can you provide some DDL + data so that I may provide a quick solution for you?
Reply With Quote
  #5 (permalink)  
Old 09-18-07, 07:11
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
First guess :

Code:
SELECT c.clientname
FROM product_categories pc
JOIN product_adcategories pa ON pc.cat_id = pa.cat_id
JOIN clientsegueads c ON c.cadid = pa.cadid
WHERE pc.cat_label = 'health'
ORDER BY RAND()
LIMIT 0,3
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