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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-03-04, 14:29
ryanf ryanf is offline
Registered User
 
Join Date: May 2004
Posts: 1
sql query problem

Hey, I am trying to get all the rows from one table as long as they are not in another. I am also using mySQL.

Here is the sql I need:
Code:
select sp.products_id, p.products_id, p.products_ordered, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " sp
where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . $languages_id. "' and p.products_ordered > 0 group by pd.products_id 
order by rand() 
DESC limit 20
but I have to make sure the results are not part of:
Code:
select products_id from specials.
Thanks for any help
Reply With Quote
  #2 (permalink)  
Old 05-03-04, 21:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
not sure why, but you already appear to have a specials table in the query

also, i can't really see why you're grouping, either

try this --
Code:
select p.products_id
     , p.products_ordered
     , pd.products_name
     , p.products_price
     , p.products_tax_class_id
     , p.products_image
  from " . TABLE_PRODUCTS . " p
inner
  join " . TABLE_PRODUCTS_DESCRIPTION . " pd
    on p.products_id 
     = pd.products_id 
   and pd.language_id = '" . $languages_id. "' 
left outer
  join " . TABLE_SPECIALS . " sp
    on p.products_id 
     = sp.products_id 
 where p.products_status = '1' 
   and p.products_ordered > 0 
   and sp.products_id is null
order 
    by rand() desc 
limit 20
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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