PDA

View Full Version : The MyChenQL insanity never ends


filburt1
03-09-2003, 10:38 PM
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:

SELECT t.userid, u.username FROM sometable t, user u WHERE t.userid = u.userid;

However I don't know what to do with two userids.

Xenon
03-10-2003, 12:04 PM
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 ;))

filburt1
03-10-2003, 12:11 PM
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.

Xenon
03-10-2003, 12:16 PM
ahhh i see now :)

well i think this should work:

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)

filburt1
03-10-2003, 12:26 PM
Trying now. I knew it would probably involve joins. :)

filburt1
03-10-2003, 12:34 PM
Unknown table 'username' in field list

...which makes sense...?

Xenon
03-10-2003, 02:06 PM
hmm, intresting ^^

retry the query now, maybe it was because of my forgotten tablenames ;)

filburt1
03-11-2003, 01:23 PM
Got it working after half-rewriting the query ;). Helped me learn about JOINs, though.

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 );