Jump to content

Output 2 joined tables


wemustdesign

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.