Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 COMPLEX QUERY NEED HELP

Author  Topic 

rajnidas
Yak Posting Veteran

97 Posts

Posted - 2014-08-02 : 02:50:52
hi all,

i need your help for following query, when we execute the query the following result is getting.



SELECT COURIERCODE,WAYBILLSTARTSERIES,WAYBILLENDSERIES FROM waybill_master
WHERE COURIERCODE IN( SELECT COURIERCODE FROM waybill_master WHERE waybillstartseries=waybillendseries)
ORDER BY WAYBILLSTARTSERIES,WAYBILLENDSERIES DESC


getting result
-----

'MAR', '25', '25'
'MAR', '26', '200'
'MAR', '26', '50'
'SUN', '100', '100'
'MOON', '200', '200'
'MOON', '201', '250'
'VENUS', '500', '500'
'EARTH', '200','200'
'EARTH', '500','500'

we need result
----------------
'SUN', '100', '100'
'VENUS', '500', '500'
'EARTH', '200','200'
'EARTH', '500','500'


IF ANY RECORD EQUAL WE NEED ONLY THAT DATA OR IF THE RECORD WITH THE SAME NAME WITH NOT EQUAL SHOULD NOT APPEAR. KINDLY NEED HELP.


THANKS

RAJNIDAS

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-08-02 : 05:41:45
[code]
SELECT *
FROM Table t
WHERE NOT EXISTS (SELECT 1
FROM Table
WHERE COURIERCODE = t.COURIERCODE
AND WAYBILLSTARTSERIES <> WAYBILLENDSERIES
)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

rajnidas
Yak Posting Veteran

97 Posts

Posted - 2014-08-02 : 06:25:06
thanks and hats off to you

you resolved my query problem.

thanks

rajnidas

Go to Top of Page
   

- Advertisement -