[SOLVED] Selecting data from 2 MySQL tables and sorting

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
h@mm3r
Forum Newbie
Posts: 10
Joined: Mon Nov 24, 2003 9:35 am

Selecting data from 2 MySQL tables and sorting

Post by h@mm3r »

I have 2 tables: the first one contains texts, the other one comments for the texts.
Like this:

1st table

Code: Select all

+----+-----------------------------------------------------+
| id | text                                                |
+----+-----------------------------------------------------+
|  1 | Some text here                                      |
|  2 | Some more text here                                 |
+----+-----------------------------------------------------+
2nd table

Code: Select all

+----+--------+---------------------------+
| id | textID | text                      |
+----+--------+---------------------------+
|  1 |      1 | This is a comment         |
|  2 |      1 | This is a comment         |
|  3 |      2 | This is a comment         |
|  4 |      2 | This is a comment         |
|  5 |      1 | This is a comment         |
|  6 |      2 | This is a comment         |
|  7 |      1 | This is a comment         |
|  8 |      2 | This is a comment         |
+----+--------+---------------------------+
Now, I want to list the texts ordered by the number of comments for each text. I think it has something to do with using multiple/selecting tables...
Can anybody help me please? :P
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=23862

add an ORDER BY to my last post in that thread.
h@mm3r
Forum Newbie
Posts: 10
Joined: Mon Nov 24, 2003 9:35 am

Post by h@mm3r »

Thanks, that helped!
Post Reply