woopata
woopata

Reputation: 875

Mysql cartesian product in where clause

What i need is cartesian product in WHERE clause:

for example i have cities London, Barcelona, Milan, Paris in one variable, and Berlin in other variable.. i need all combinations in where clause (london-berlin, barcelona-berlin, milan-berlin, paris-berlin).

SELECT *
FROM flight
WHERE flight.from = (London, Barcelona, Milan, Paris) AND flight.to = 'Berlin'

Upvotes: 0

Views: 350

Answers (2)

Joachim Isaksson
Joachim Isaksson

Reputation: 180947

If flight.from is a char/varchar, try;

SELECT * FROM flight 
    WHERE `from` IN ('London', 'Barcelona', 'Milan', 'Paris') AND `to`='Berlin'; 

Upvotes: 1

Marc B
Marc B

Reputation: 360742

Try:

WHERE flight.from IN ('London', 'Barecelona', 'Milan', 'Paris') AND (flight.to = 'Berlin')

Upvotes: 2

Related Questions