Quantcast
Channel: Questions in topic: "distinct"
Viewing all articles
Browse latest Browse all 38

SQL Union Operator

$
0
0
Hi, Here is the example query. Query1: Select supp_addr_addid 'billtoaddid' from supp_addr_address(nolock), supp_bu_suplmain (nolock) where supp_addr_supcode = supp_bu_supcode and supp_addr_supcode = '12069' and supp_addr_addid = supp_bu_deforderto billtoaddid ----------- 2 (1 row(s) affected) Query 2: Select supp_addr_addid 'billtoaddid' from supp_addr_address(nolock), supp_bu_suplmain (nolock) where supp_addr_supcode = '12069' and supp_addr_supcode = supp_bu_supcode and supp_addr_loid = 'MJBLO' and supp_addr_supcode in ( select supp_ou_supcode from supp_ou_suplmain (nolock) where supp_ou_ouinstid = 3 and supp_ou_supcode = '12069' ) Query 2 output: billtoaddid ----------- 1 2 (2 row(s) affected) I Need to write union for the query 1 and query 2 but the result set of the query 1 should come first. If i write the union query as below, Select supp_addr_addid 'billtoaddid' from supp_addr_address(nolock), supp_bu_suplmain (nolock) where supp_addr_supcode = supp_bu_supcode and supp_addr_supcode = '12069' and supp_addr_addid = supp_bu_deforderto union Select supp_addr_addid 'billtoaddid' from supp_addr_address(nolock), supp_bu_suplmain (nolock) where supp_addr_supcode = '12069' and supp_addr_supcode = supp_bu_supcode and supp_addr_loid = 'MJBLO' and supp_addr_supcode in ( select supp_ou_supcode from supp_ou_suplmain (nolock) where supp_ou_ouinstid = 3 and supp_ou_supcode = '12069' ) The output comes as below. billtoaddid ----------- 1 2 (2 row(s) affected) I need a output of query 1 to come first. Please help any question let me know. Thanks Satish

Viewing all articles
Browse latest Browse all 38

Trending Articles