2012-05-11 41 views
0

我想在我的mysql数据库上做一件事。如何从两个表中选择列并按其中一个排序?

我有两个表:

first_table:

| article   | longtext    | YES |  | NULL |    | 
| article_id  | int(11)    | YES |  | NULL |    | 

Second_table:

| id | int(11) | 
| name | longtext | 
| commit_date | date | 

当first_table.article_id = second_table.id,然后文章=名称。

我想从第一个表中选择article和article_id,并按第二个表中的commit_date(对每个记录都是正确的)对它们进行排序。

怎么办?

回答

0

看看下面的查询,应该做你想要什么:

SELECT article, article_id 
FROM first_table f 
JOIN Second_table s ON f.article_id = s.id AND f.article = s.name 
ORDER BY s.commit_date 
相关问题