SELECT Users.ID, Users.UserName, Comments.Description FROM Users LEFT JOIN Comments ON Users.ID = Comments.UserID;
(note that you'll need to have the UserID foreign key in your Comments table. Also, the "LEFT JOIN" phrase tells whatever sql back-end you're using that you want -all- records from the users table, regardless of whether or not they have a comment-- and any comments per user in the comments table. If you want to eliminate users who don't have comments, use an INNER JOIN instead.
Bruno Braga wrote:
I have these tables.
Users ( id,name,etc )
Coments : ( id , comment )
How do I do this kind of query:
I thought in one thing like this but I cant figure it out.
Example: Select * from users order by id desc in (select count (id) from comments)
List of users:
See comments ( 32 comment in database )
See coments (13 comments in database )
thanks in advanced.
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php