Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHERE IN statement isn't working correctly...

Status
Not open for further replies.

tsyle

Programmer
May 16, 2005
35
US
Select U.user_id, U.Username, U.timestamp, U.account_type
From users U
Where U.user_id IN (Select T.user_id
From txnlog T
Where T.result = 'Cash Paid'
Group By T.user_id)

This is the code that I am working with. I don't know where i'm going wrong but PHPAdmin keeps telling me that I have a syntax error. I have copied the error below.

#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Select T.user_id

I have no idea why this isn't working. When i use Where U.user_id IN ('1','2','3') it works... Please help
From txnlog T
 
oh... My version is 4.0... if i update it will i lose all my tables?
 
no, you will retain all info, just be sure to back up before .. just in case*.



*as we all know how things which can go badly wrong, always will.



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
most subqueries can be rewritten as joins
Code:
select U.user_id
     , U.Username
     , U.timestamp
     , U.account_type
  from users U
inner
  join txnlog T
    on U.user_id = T.user_id
   and T.result = 'Cash Paid'
group 
    by U.user_id
     , U.Username
     , U.timestamp
     , U.account_type

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top