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 > subquery doesn't work in mysql (was "SQL Statement Help needed")

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-07-05, 16:28
mamin mamin is offline
Registered User
 
Join Date: Oct 2003
Posts: 24
subquery doesn't work in mysql (was "SQL Statement Help needed")

I am having issue with query which works in MS SQL But does not work in MySQL..Can someone help me how can I do same or similar with MY SQL..

My MS SQL Statement is as follows

select * from products where categoryid in (select distinct categoryid from tblcart,products where products.sku = tblcart.productid and cartID='767867867868')


How can achieve same with mySQL ?
Reply With Quote
  #2 (permalink)  
Old 03-07-05, 16:52
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
the only thing that could possible be wrong is that you aren't on the current release, 4.1, which has been in production status since october, and which supports subqueries
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-07-05, 16:54
mamin mamin is offline
Registered User
 
Join Date: Oct 2003
Posts: 24
Quote:
Originally Posted by r937
the only thing that could possible be wrong is that you aren't on the current release, 4.1, which has been in production status since october, and which supports subqueries
I have ticket open with my hosting company on version as you mentioned. Let say they do not have 4.1 installed then what should I do..I have to write two queries to do this task ?...
Reply With Quote
  #4 (permalink)  
Old 03-07-05, 17:08
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
caution: untested --
Code:
select p2.* 
  from tblcart 
inner
  join products as p1
    on tblcart.productid 
     = p1.sku 
inner
  join products as p2
    on p1.categoryid
     = p2.categoryid
 where cartID = '767867867868'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-07-05, 17:21
mamin mamin is offline
Registered User
 
Join Date: Oct 2003
Posts: 24
Quote:
Originally Posted by r937
caution: untested --
Code:
select p2.* 
  from tblcart 
inner
  join products as p1
    on tblcart.productid 
     = p1.sku 
inner
  join products as p2
    on p1.categoryid
     = p2.categoryid
 where cartID = '767867867868'
Thank you for your help...I will try and let you know
Reply With Quote
  #6 (permalink)  
Old 03-07-05, 17:37
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
if the cart contains multiple products from the same category, you may need to add the word DISTINCT after the word SELECT
__________________
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