Reputation: 35
I am newbie in mysql.Suppose you have a database table named 'table1':
id cityA cityB producer
_____________________________
1 Rome Berlin Alan
2 Vienna Hanover Max
3 Rome Berlin Peter
4 London Siena John
First,i want to get the row where producer is Alan:
$query = "
SELECT cityA , cityB , producer
FROM table1
WHERE table1.producer = 'Alan'
";
that returns row id =1. How can i get now all rows that have same cityA,cityB as row 1 at the same php script, i mean not using second ajax call;
Expecting result:
1 Rome Berlin Alan
3 Rome Berlin Peter
Upvotes: 0
Views: 33
Reputation: 204854
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
Upvotes: 2