Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Quote:
Here is the image that contain the DB tables
Image


Quote:
This is the Query

SQL
SELECT     bus_root_station.bid, root_station.rsid, root_station.rid, bus_station.sid, bus_station.sname, bus.b_no, sorc.sname AS sorc, Desti.sname AS desti
FROM         bus_root_station INNER JOIN
                      root_station ON bus_root_station.rsid = root_station.rsid INNER JOIN
                      bus_root ON root_station.rid = bus_root.rid INNER JOIN
                      bus_station ON root_station.sid = bus_station.sid INNER JOIN
                      bus ON bus_root_station.bid = bus.bid AND bus_root.rid = bus.rid INNER JOIN
                      Bus_type ON bus.btid = Bus_type.btid INNER JOIN
                      bus_station AS sorc ON bus_root.src_id = sorc.sid INNER JOIN
                      bus_station AS Desti ON bus_root.dest_id = Desti.sid

where root_station.rsid between  

(

SELECT     root_station_2.rsid
FROM         bus_root_station AS bus_root_station_2 INNER JOIN
                      root_station AS root_station_2 ON bus_root_station_2.rsid = root_station_2.rsid INNER JOIN
                      bus_station AS bus_station_2 ON root_station_2.sid = bus_station_2.sid INNER JOIN
                      bus ON bus_root_station_2.bid = bus.bid
WHERE     (root_station_2.sid = 102)

) and (


SELECT     root_station_2.rsid
FROM         bus_root_station AS bus_root_station_2 INNER JOIN
                      root_station AS root_station_2 ON bus_root_station_2.rsid = root_station_2.rsid INNER JOIN
                      bus_station AS bus_station_2 ON root_station_2.sid = bus_station_2.sid INNER JOIN
                      bus ON bus_root_station_2.bid = bus.bid
WHERE     (root_station_2.sid = 101))

order by root_station.rsid


Quote:
I want to also get the bues that have have same root.

like

busNo bus-root
A123 delhi-alwar-jaipur-KG-ajmer-jodhpur
B125 jaipur-KG-ajmer-bhilwara-udaipur

when i have enter jaipur to ajmer then here this error is occoured.


Errror:Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Posted
Updated 9-Apr-14 1:51am
v2

where root_station.rsid between

(

SELECT TOP 1 root_station_2.rsid
FROM bus_root_station AS bus_root_station_2 INNER JOIN
root_station AS root_station_2 ON bus_root_station_2.rsid = root_station_2.rsid INNER JOIN
bus_station AS bus_station_2 ON root_station_2.sid = bus_station_2.sid INNER JOIN
bus ON bus_root_station_2.bid = bus.bid
WHERE (root_station_2.sid = 102)

) and (


SELECT TOP 1 root_station_2.rsid
FROM bus_root_station AS bus_root_station_2 INNER JOIN
root_station AS root_station_2 ON bus_root_station_2.rsid = root_station_2.rsid INNER JOIN
bus_station AS bus_station_2 ON root_station_2.sid = bus_station_2.sid INNER JOIN
bus ON bus_root_station_2.bid = bus.bid
WHERE (root_station_2.sid = 101))

order by root_station.rsid
 
Share this answer
 
Comments
ashwani soft 9-Apr-14 7:56am    
but i want to both values to get whole result.
I want to also get the bues that have same root.
[no name] 9-Apr-14 8:01am    
condition wants to check single statement to a single when it's returning more than one row it's throwing error to you. That's why you need top 1 or you can check it by distinct also.
Between works with two values Start Range to End Range. On of your sub query is returning multiple values which violates between rule. Change the logic to fetch single value or use Min in first sub query and Max in second.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900