Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: help with a join query
10-02-2011, 06:33 PM #1
- Join Date
- Jul 2010
- Thanked 18 Times in 18 Posts
help with a join query
Here's the query what's causing me some trouble.
SELECT ar.ID as aID, ar.username as auser, ar.refID, m.user_id,m.username as muser FROM ag_refered ar LEFT JOIN members m ON ('m.user_id' = 'ar.refID')
ID = 1
username = SomeUser
refID = 96
and in the members table i have a record
user_id = 96
username = testRefer
yet when i run the query in something like PHPMyAdmin i get this
aID | auser | refID | user_id | muser
1 | SomeUser | 96 | NULL | NULL
Can anyone see why?
EDIT: Both tables are in the same database and the correct database is defined in my connection. If also tried the ON ('m.user_id' = 'ar.refID') like ON ('ar.refID' = 'm.user_id') too and i get the same reuslt
Last edited by tomharto; 10-02-2011 at 06:41 PM.
10-03-2011, 12:33 AM #2
- Join Date
- Jun 2008
- New Jersey
- Thanked 259 Times in 256 Posts
Because as far as mySQL is concerned, you're joining where two (different) strings are the same. By putting it in quotes, its interpreting m.user_ID and ar.refID as strings, so...
Code:SELECT ar.ID as aID, ar.username as auser, ar.refID, m.user_id,m.username as muser FROM ag_refered ar LEFT JOIN members m ON m.user_id = ar.refID