Question : Select Data From Two Tables And show distinct  records and second  table records come first then  first table record and having relationship.

Suppose i have table name tblfavuser(Contains data of favorite user)    and tbluser(contains the user data). I  want to show distinct record from both table and tblfavuser comes first then tbluser.

Answer : Select Data From Two Tables And show distinct  records and second  table records come first then  first table record and having relationship.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
col ordertype noprint
 
SELECT 1 ordertype, tblfavuser.*
  FROM tblfavuser
  WHERE not exists (select 1
                                    from tbluser
                                   where tbluser.id = tblfavuser.id)
UNION
SELECT 2, tbluser.*
   FROM tbluser
 WHERE not exists (select 1
                                    from tblfavuser
                                   where tblfavuser.id = tbluser.id)
order by 1
Open in New Window Select All
Random Solutions  
 
programming4us programming4us