0

I have this query:

SELECT s.* FROM  stop s 
WHERE 
s.hour>
        (SELECT st.hours FROM stop st
             JOIN City cit ON cit.id = st.idCity
             WHERE cit.name = 'LA' ) 

But the subquery returns more than one row, how should I proceed?

City

id name
1 LA
2 Ny
3 AZ

Stop

id Hour idCity idCityB
1 7:00 1 2
2 8.00 2 1
3 9:00 3 2
5 10:00 1 2
6 11:00 3 2

I want 8:00, 9:00 and 11:00

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
gianluca23
  • 23
  • 5

1 Answers1

0

Possible realizations (use those which matches needed logic if present):

SELECT s.* 
FROM stop s
JOIN stop st USING (`hour`)
JOIN city cit ON cit.id = st.idcity
WHERE cit.name <> 'LA' 
SELECT s.* 
FROM  stop s 
WHERE hour NOT IN ( SELECT st.`hour` 
                    FROM stop st 
                    JOIN city cit ON cit.id = st.idcity
                    WHERE cit.name = 'LA' ) 

On your sample data both queries gives the same desired output, but their logic differs and they will give different output on another data.

Akina
  • 39,301
  • 5
  • 14
  • 25