sql server - SQL joining table with two different alias -
i joining 2 tables selecting records on basis of query first table construction user table==>
userid fname lname
second table agents table ==>
id agentid managerid
where agentid , managerid foreign key,which contains userid of first table have retrieve records on basis of first name of 1 either manager or agent, writing this
select u.userid,u.fname,u.lname,a.managerid user u left bring together agents on u.userid=a.agentid u.fname '%anyname%'
it returning agents have name anyname, want homecoming managers ie bring together agents table 1 time again users table on managerid time, how can this?
i think you're looking this:
select u.userid,u.fname,u.lname,a.managerid user u left bring together agents on u.userid=a.agentid u.fname '%anyname%' union select u.userid,u.fname,u.lname,a.managerid user u left bring together agents on u.userid=a.managerid u.fname '%anyname%'
sql sql-server
No comments:
Post a Comment