我有两张桌子:
tbl_post和tbl_public
tbl_post:
id | post_id | author | date (unix time)
--------------------------------
0 | 123456 | User 1 | 1489857236
1 | 123457 | User 2 | 1489857237
2 | 123458 | User 3 | 1489857238
tbl_public:
id | post_id | public | date (unix time)
-----------------------------------------
--> 0 | 123456 | 0 | 1489857236
1 | 123457 | 1 |
2 | 123458 | 0 |
--> 3 | 123456 | 1 | 1489857239
我希望得到user =“User 1”的所有行,并且表tbl_public中的最新(按日期排序)公共列大于0日期DESC
你能帮我查询一下命令吗? :)
答案 0 :(得分:0)
你可以通过使用INNER JOIN来实现这一点,这是sintax吼叫:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
答案 1 :(得分:0)
请简要详细说明您的需求,但我尝试了从您的问题中理解的内容。让我知道它是否适合你。
Sql:SELECT tp.post_id, tp.author, tpb.public, tpb.date FROM tbl_post tp LEFT JOIN tbl_public tpb ON (tp.post_id = tpb.post_id) WHERE tp.author = 'User 1' ORDER BY tpb.date DESC;
答案 2 :(得分:0)
从tbl_post中选择*' a'内联合tbl_public' b'在a.post_id = b.post_id上,作者='用户1'和公众> 0