Jump to content

Archived

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

chris_davidsonuk

Join tables

Recommended Posts

I am creating a music website. Users must be verified by the admin before their songs are published on the site. I have 2 tables:

[b]USERS[/b]
- Username
- Status (This is set to 1 if verified 0 if not)

[b]TRACKS[/b]
- Username

I am wanting to query the database and show the tracks (from the tracks table) by users that have been verified (taken from the users table).

I have looked at many tutorials but can't get this to word. Does anybody know the correct syntax for this query?

Any help much appreciated.

Share this post


Link to post
Share on other sites
Is this what you are after?

SELECT tracks.*, status FROM tracks, users where user.status = 1;

ps I don't see why username is in the tracks database should it be songname?

Share this post


Link to post
Share on other sites
If you are using Username in both tables to do the join then try

Select * FROM tracks NATURAL JOIN users;

Share this post


Link to post
Share on other sites
Where are the UIDs? Tell me your primary key isn't a (VAR)CHAR field... that's a no-no, at least for MyISAM tables.  Besides, you should use a proper JOIN:

SELECT tracks.*FROM tracks INNER JOIN users ON ( tracks.username = user.username ) where user.status = 1;

Share this post


Link to post
Share on other sites

×

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.