Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Same column name from two tables satisfying two conditions

I need some quick help on SQL. This is basic for most I am sure.

I want to select orderId in both tables merged that satisfies status = 1.

Please find example of the two table tb1 and tb2 here:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

tb1

orderId  status
---------------
001     0
003     1
005     1
007     1
...

tb2

orderId  status
----------------
002      1
008      1
004      0

>Solution :

You can use UNION ALL.

Your query would be:

SELECT *
FROM (
   SELECT *
   FROM tb1

   UNION ALL

   SELECT *
   FROM tb2
) a
WHERE STATUS = 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading