sqlsql-serverstored-proceduresplsql

find between places


  1. I Have a table tblroute_details

enter image description here

  1. I want to find between places, I used that query

    SELECT (placeName) 
      FROM tblRouteDetails
     WHERE ID Between (
            SELECT  ID 
              FROM tblRouteDetails 
              WHERE placeName = 'Kaushambi' ) 
         AND (SELECT ID 
              FROM tblRouteDetails 
              WHERE placeName = 'Ghaziabad') 
    

    ORDER BY ID

It gives error

Msg 512, Level 16, State 1, Line 3
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Solution

  • SELECT id, placeName FROM tblRouteDetails 
    WHERE placeName in ('Kaushambi','Ghaziabad') 
    ORDER BY ID