PHP MySQL连接

PHP MySQL连接,php,mysql,arrays,join,Php,Mysql,Arrays,Join,有没有办法让我做到以下几点 表一 id c_id type ------------------- 1 1 7 2 2 7 3 3 5 4 4 7 表二 id title live ------------------- 1 row1 1 2 row2 0 3 row3 0 4 row4 1 c_id列将表1中的数据链接到表2。示例:在表1中,如果c_id为

有没有办法让我做到以下几点

表一

id   c_id   type
-------------------
1    1       7
2    2       7
3    3       5
4    4       7
表二

id   title   live
-------------------
1    row1    1
2    row2    0
3    row3    0
4    row4    1
c_id列将表1中的数据链接到表2。示例:在表1中,如果c_id为2,则表1中的该行将直接链接到表2中id为2的行,该行的标题为row2

我想从表1中选择类型为7的所有内容,但前提是表2中的关联数据已设置为1

select * from one join two on c_id = two.id where type=7 and live = 1
order by one.id desc limit 5
我是这样想的,但这似乎不起作用:

SELECT * FROM ONE, TWO WHERE ONE.type='7' AND TWO.live='1' ORDER BY ONE.id DESC LIMIT 5

我希望上面的代码只返回表1中的第1行和第4行,因为尽管表1中有三行的类型为7,但表2中只有第1行和第2行的关联行的活动设置为1。

您很接近。。。尝试使用隐式联接:

select * from one join two on c_id = two.id where type=7 and live = 1
order by one.id desc limit 5
SELECT ONE.* FROM ONE, TWO WHERE ONE.type='7' AND TWO.live='1' AND ONE.c_id = TWO.id ORDER BY ONE.id DESC LIMIT 5

它实际上返回了什么?您缺少连接谓词。谢谢!我认为这是可行的。我只需要将SELECT ONE.*从一改为SELECT*从一,因为我想返回两个表中的所有数据。不过,我可能没有在我的问题中说明这一点。再次感谢: