I have a mysql comment table like this.
+------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | userid | int(11) | NO | | 0 | | | comment | char(255) | NO | | NULL | | | content | int(11) | NO | MUL | 0 | | | ratings | int(11) | NO | | 0 | | | datetime | datetime | NO | | NULL | | | ip | int(10) unsigned | NO | | NULL | | | is_updated | tinyint(2) | NO | | 0 | | | record_num | int(11) | NO | PRI | NULL | auto_increment | +------------+------------------+------+-----+---------+----------------+
now I can get comments from this and usernames from another table using an INNER JOIN query like this.
I can get 3 top comments ORDER BY comments.ratings DESC
SELECT comments.userid, users.username, comments.comment, comments.ratings, comments.datetime, comments.record_num , content.uploader , content.anonymous FROM comments LEFT JOIN users ON comments.userid = users.record_num LEFT JOIN content ON comments.content = content.record_num WHERE comments.content = ? ORDER BY comments.ratings DESC limit 3
and
regular comments ORDER BY comments.datetime DESC.
SELECT comments.userid, users.username, comments.comment, comments.ratings, comments.datetime, comments.record_num , content.uploader , content.anonymous FROM comments LEFT JOIN users ON comments.userid = users.record_num LEFT JOIN content ON comments.content = content.record_num WHERE comments.content = ? ORDER BY comments.datetime DESC limit ?, ?
what I'm trying to do is show users the first 3 comments by their ratings first, and then the regular order of comments by comments. datetime DESC.
Now, how can I join two mysql queries in one?
join php mysql
Amb
source share