我是mysql的新手。假设你有一个名为'table1'的数据库表:
id cityA cityB producer
_____________________________
1 Rome Berlin Alan
2 Vienna Hanover Max
3 Rome Berlin Peter
4 London Siena John
首先,我想得到生产者是艾伦的行:
$query = "
SELECT cityA , cityB , producer
FROM table1
WHERE table1.producer = 'Alan'
";
返回行id = 1。 我现在如何获得在同一个php脚本中具有相同cityA,cityB和第1行的所有行,我的意思是不使用第二个ajax调用;
期待结果:
1 Rome Berlin Alan
3 Rome Berlin Peter
答案 0 :(得分:2)
select t1.*
from table1 t1
join
(
SELECT cityA, cityB
FROM table1
WHERE producer = 'Alan'
) t2 on t1.cityA = t2.cityA and t1.cityB = t2.cityB