0

我如何获得最大值 MESSAGENUMBER

mysql> 
mysql> describe ARTICLE;describeNEWSGROUP;
+---------------+------------+------+-----+---------+----------------+
| Field         | Type       | Null | Key | Default | Extra          |
+---------------+------------+------+-----+---------+----------------+
| ID            | bigint(20) | NO   | PRI | NULL    | auto_increment |
| MESSAGENUMBER | int(11)    | YES  |     | NULL    |                |
| NEWSGROUP_ID  | bigint(20) | YES  | MUL | NULL    |                |
+---------------+------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| ID        | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| NEWSGROUP | varchar(255) | YES  |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> 
mysql> select * from ARTICLE left join NEWSGROUP on ARTICLE.NEWSGROUP_ID=NEWSGROUP.ID where NEWSGROUP.newsgroup = "gwene.com.economist";
+----+---------------+--------------+------+---------------------+
| ID | MESSAGENUMBER | NEWSGROUP_ID | ID   | NEWSGROUP           |
+----+---------------+--------------+------+---------------------+
| 18 |             4 |            4 |    4 | gwene.com.economist |
| 19 |             5 |            4 |    4 | gwene.com.economist |
| 20 |             6 |            4 |    4 | gwene.com.economist |
| 21 |             7 |            4 |    4 | gwene.com.economist |
| 22 |             8 |            4 |    4 | gwene.com.economist |
| 23 |             9 |            4 |    4 | gwene.com.economist |
| 24 |            10 |            4 |    4 | gwene.com.economist |
| 25 |            11 |            4 |    4 | gwene.com.economist |
+----+---------------+--------------+------+---------------------+
8 rows in set (0.00 sec)

mysql> 
4

2 回答 2

1
select * from ARTICLE left join NEWSGROUP 
on ARTICLE.NEWSGROUP_ID=NEWSGROUP.ID 
where NEWSGROUP.newsgroup = "gwene.com.economist" 
ORDER BY MESSAGENUMBER DESC LIMIT 1
于 2012-08-04T09:25:29.043 回答
1
SELECT MAX(MESSAGENUMBER)
FROM ARTICLE left join NEWSGROUP on ARTICLE.NEWSGROUP_ID=NEWSGROUP.ID 
WHERE NEWSGROUP.newsgroup = "gwene.com.economist"
于 2012-08-04T09:31:45.910 回答