The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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 ) |
#3
|
|||
|
|||
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.
|
#4
|
||||
|
||||
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] |
#5
|
|||
|
|||
Trying now. I knew it would probably involve joins.
|
#6
|
|||
|
|||
Code:
Unknown table 'username' in field list |
#7
|
||||
|
||||
hmm, intresting ^^
retry the query now, maybe it was because of my forgotten tablenames |
#8
|
|||
|
|||
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] |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|