I have a troubled SQL statement that sounds simple but it looks terrible. I want to be ordered to return the SQL with a result with the YouTube data so that a certain user is the first line in the form of a result, if that user is in the table of companies related to email.
I have this SQL which deserves me but I think it looks terrible:
select 1 as o, * user where companyid = 1 and email = (Select email from companies where id = 1) chooses o from union 2, * user u from where companyid = 1 and email & lt; & Gt; (Select from e-mail from companies where id = 1) o
By order and by the way, the email address from the user table can be in many companies so that no e-mail address is included Not possible.
Using Microsoft SQL Server 2000
Edit: I is using:
P>
select * , When u.email = (Select the email from companies where id = 1) then the end of 1 and 2 is sorted as user, where u.companyId = 1 order SortMeFirst
< P> I think it's more beautiful. Thanks Richard L.
you can do something like this ..
when it exists Then select the case (Choose from companies C Email, where CID = u.ID and c.Email = u.Email) then 1 ELSE 2 END as SortMeFirst * User from where Company Id = 1 SortMeFirst By <1 Order>
Comments
Post a Comment