从两个sql查询中选择常见结果

时间:2015-08-07 09:39:51

标签: mysql

查询1:

Select route_stop.Route_ID from route_stop,stop where
  route_stop.Stop_ID=stop.Stop_ID AND stop.Stop_Name='Agargaon'

查询2:

Select route_stop.Route_ID from route_stop,stop where
  route_stop.Stop_ID=stop.Stop_ID AND stop.Stop_Name='Mirpur-12'

4 个答案:

答案 0 :(得分:2)

Select route_stop.Route_ID from route_stop,stop where route_stop.Stop_ID=stop.Stop_ID AND stop.Stop_Name='Agargaon'
Union
Select route_stop.Route_ID from route_stop,stop where route_stop.Stop_ID=stop.Stop_ID AND stop.Stop_Name='Mirpur-12'

要加入同一列,请使用union

答案 1 :(得分:0)

按照以下方式使用 -

SELECT route_stop.Route_ID 
FROM route_stop,STOP 
WHERE route_stop.Stop_ID=stop.Stop_ID AND stop.Stop_Name IN ('Agargaon','Mirpur-12')

答案 2 :(得分:0)

SELECT Route_ID FROM route_stop JOIN stop ON route_stop.Stop_ID = stop.Stop_ID WHERE stop.Stop_Name =' Agargaon'或者stop.Stop_Name =' Mirpur-12'

答案 3 :(得分:0)

你可以试试这个,交配:

SELECT
    rs.Route_ID
FROM
    route_stop rs
    INNER JOIN stop s ON s.Stop_ID = rs.Stop_ID
WHERE
    s.Stop_Name IN ('Agargaon', 'Mirpur-12')
GROUP BY
    rs.Route_ID;