加入表并过滤它#mysql

时间:2017-12-04 02:55:19

标签: mysql filter jointable

我在JOIN TABLE之后遇到过滤表的问题。
如你所见,我这里有2张桌子。
表1

Image table1

表2

image table2

我在表1中进行过滤,没有使用JOIN JOIN,如下所示:

SELECT * FROM table1 WHERE id IN (
    SELECT MAX(id) AS id_a 
    FROM tabel1 GROUP BY id_a ) 
ORDER BY id DESC

我的结果是这样的:

enter image description here,我完全想要它。

问题是:如何加入2表(table1和table2)并得到像我这样做过滤器表1的结果:

Join Table and filter it

我希望你理解我的问题,请帮助我。

1 个答案:

答案 0 :(得分:0)

这是您需要的伪查询:

SELECT MAX(a.id), a.id_a, a.value, a.datetime,b.weight
FROM table1 a
LEFT JOIN table b ON(a.id_a = b.id_a)
GROUP BY a.id_a
ORDER BY datetime DESC