wemustdesign Posted June 12, 2010 Share Posted June 12, 2010 I have 2 tables with username in both tables. Here are the two tables: USERS ------------------------------ username name telephone COURSES ------------------------------ username date courseID I am wanting to output as: name | telephone | date | How would I go about doing this in php? Link to comment https://forums.phpfreaks.com/topic/204565-output-2-joined-tables/ Share on other sites More sharing options...
Mchl Posted June 12, 2010 Share Posted June 12, 2010 SELECT u.username, u.telephone, c.date FROM users AS u CROSS JOIN courses AS c USING (username) Side note: using username as a foreign key might not be the best idea. Link to comment https://forums.phpfreaks.com/topic/204565-output-2-joined-tables/#findComment-1071116 Share on other sites More sharing options...
Daniel0 Posted June 12, 2010 Share Posted June 12, 2010 SELECT u.username, u.telephone, c.date FROM users AS u CROSS JOIN courses AS c USING (username) Side note: using username as a foreign key might not be the best idea. Assuming that username is primary key (or just any key) in the other table, that would be perfectly fine. Link to comment https://forums.phpfreaks.com/topic/204565-output-2-joined-tables/#findComment-1071141 Share on other sites More sharing options...
Mchl Posted June 12, 2010 Share Posted June 12, 2010 It would be fine, but I would drop 'perfectly' from this statement It will work of course, but has some serious drawbacks. Allowing users to change their usernames is no longer easy. String indexes tend to be larger and slower than integer. If users are allowed to have really long usernames, a lot of storage is wasted on storing this information again and again. Link to comment https://forums.phpfreaks.com/topic/204565-output-2-joined-tables/#findComment-1071143 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.