How do I do this select?
| From: | Chris W | Date: | Sun, 11 Jan 2004 14:13:23 +0000 |
| Subject: | How do I do this select? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-174240@lists.php.net to get a copy of this message | ||
I sent this to the mysql list but it doesn't seem to be working so I was hoping someone here could help.
I have the following 2 tables.
CREATE TABLE User (
UserKey INT NOT NULL AUTO_INCREMENT,
UserID CHAR(16) NOT NULL UNIQUE , Name VARCHAR(20),PRIMARY KEY (UserKey) ); CREATE TABLE FriendList(
UserKey INT NOT NULL,FriendKey INT NOT NULL, PRIMARY KEY (UserKey, FriendKey) ); The second table is a many to many relationship table. I want to select every row from FriendList and link it to userID so the out put looks something like this. UserID FriendID FriendName
a x x-name a y y-name a z z-name b a a-name b c c-name b z z-name c b b-name c x x-nameThis will give me sort of what I am looking for, but it shows the UserKey in the first column and I want the UserID. I have tried a few others but just got errors. SELECT f.UserKey, UserID FriendID, Name FriendName FROM User u, FriendList f WHERE f.FriendKey = u.UserKey ORDER BY f.UserKey, FriendID;