![]() |
The MyChenQL insanity never ends
Let's say I have two userids in one row, and I want a query to return the associated usernames with those userids. Normally I'd do this:
[sql] SELECT t.userid, u.username FROM sometable t, user u WHERE t.userid = u.userid; [/sql] However I don't know what to do with two userids. |
hmm, sorry, i've read your post threa times now and don't get what you mean by two userid's in a row...
can you please explain it a bit more to me, and what you want to have (paint a picture for dummy-me ;)) |
1 Attachment(s)
Here's the schema for the table in question. What I want to do is first show off this kickass RDC on a Mac, and second get the usernames for both fromuserid and touserid.
|
ahhh i see now :)
well i think this should work: [sql]SELECT *.usertouserlog, username.fromuser AS fromusername, username.touser AS tousername FROM usertouserlog LEFT JOIN user AS fromuser ON (usertouserlog.fromuserid=fromuser.userid) LEFT JOIN user AS touser ON (usertouserlog.touserid = touser.userid)[/sql] |
Trying now. I knew it would probably involve joins. :)
|
Code:
Unknown table 'username' in field list |
hmm, intresting ^^
retry the query now, maybe it was because of my forgotten tablenames ;) |
Got it working after half-rewriting the query ;). Helped me learn about JOINs, though.
[sql] ELECT usertouserlog. * , fromuser.username AS fromusername, touser.username AS tousername FROM usertouserlog LEFT JOIN user AS fromuser ON ( usertouserlog.fromuserid = fromuser.userid ) LEFT JOIN user AS touser ON ( usertouserlog.touserid = touser.userid ); [/sql] |
All times are GMT. The time now is 08:57 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|