sql - Get Match Data On top -
i have multiple operator on different columns below:
select d.id ,d.dealercode,d.affiliationcode,d.legalname,d.shippercode,d.primaryuserid,d.primarycontactid, dealer d left join country c on c.id=d.countryid left join [user] u on u.id=d.primaryuserid left join registrationsource rs on rs.id=d.registrationsourceid d.tenantid='4c0a42de-6ce5-4faa-8b5d-da4d7c3294b4' , ( u.username '%aq%' or d.dealercode '%aq%' or d.legalname '%aq%' or d.shippercode '%aq%' ) order d.dealercode asc
is possible find row set first(on top) have exact match value 1 of these column value
try union - should allow list 2 sets of data 1 after other (untested):
select d.id ,d.dealercode,d.affiliationcode,d.legalname, ... dealer d left join country c on c.id=d.countryid left join [user] u on u.id=d.primaryuserid left join registrationsource rs on rs.id=d.registrationsourceid d.tenantid='4c0a42de-6ce5-4faa-8b5d-da4d7c3294b4' , ( u.username = 'aq' or d.dealercode = 'aq' or d.legalname = 'aq' or d.shippercode = 'aq' ) union select d.id , d.dealercode,d.affiliationcode, ... dealer d left join country c on c.id=d.countryid left join [user] u on u.id=d.primaryuserid left join registrationsource rs on rs.id=d.registrationsourceid d.tenantid='4c0a42de-6ce5-4faa-8b5d-da4d7c3294b4' , ( u.username '%aq%' or d.dealercode '%aq%' or d.legalname '%aq%' or d.shippercode '%aq%' ) order d.dealercode asc
if there more "first one" might have restrict using top 1
Comments
Post a Comment