-1

In my example where name like '' show all value tabl2 with tabl1

SELECT * 
FROM
    (SELECT 
         ID, names, NULL AS address, work, note
     FROM   
         Tabl1
     UNION  
     SELECT 
         ID, name, address, NULL, NULL
     FROM   
         Tabl2) as x
ORDER BY 
    id, note DESC, address

enter image description here

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Sraj Muneer
  • 27
  • 2
  • 8

2 Answers2

0

With CTE_NAME(ID, names) --Column names for Temporary table AS ( SELECT ID , NAME FROM TABLE1 UNION SELECT ID , NAME FROM TABLE2

) SELECT * FROM CTE_NAME --SELECT or USE CTE temporary Table WHERE name = "x" ORDER BY ID

Vivek
  • 405
  • 1
  • 4
  • 14
0

You'll need to use UNION to combine the results of two queries. In your case:

SELECT ID, names, NULL AS address, work, note
FROM Tabl1
GROUP BY names
UNION ALL
SELECT ID, name, address, NULL, NULL
FROM Tabl2
GROUP BY Tabl3

Note - If you use UNION ALL as in above, it's no slower than running the two queries separately as it does no duplicate-checking.

Can Uzun
  • 80
  • 1
  • 13