in where condition emplyee details is exist in a table eg:table1 then take data from table1 .employee data not exists then take data from another table eg:table2 .
How to do this in where condition
in where condition emplyee details is exist in a table eg:table1 then take data from table1 .employee data not exists then take data from another table eg:table2 .
How to do this in where condition
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Nov 26, 2022, 8:26 AM EST
IF Exists (select count(1) from table1) begin select * from table1 end else begin select * from table2 endAravind GovindarajRank #430 · 5.8K reputationPosted Nov 26, 2022, 6:39 PM EST
In this case, you can approach if exists a statement or else creates a view internally to apply the union to all required tables. just get it from there....
Aradhana TripathiRank #509 · 4.8K reputationPosted Feb 9, 2023, 12:26 PM EST
You can do this simply using SQL left join clause.
select * from table1 left join table2 on table1.id = table2.id where table2.id is null;Jignesh KumarRank #91 · 22.9K reputationPosted Feb 9, 2023, 11:30 PM EST
Hello Lejo,
You can use except to achieve your requirement,
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 9, 2023, 11:44 PM EST
You can use below query for the same.
SELECT COALESCE(table1.employee_details, table2.employee_details) AS employee_details FROM table1 LEFT JOIN table2 ON table1.employee_id = table2.employee_idThanks
Rajeev KumarRank #1,334 · 1.3K reputationPosted Mar 2, 2023, 8:43 AM EST
Hi you use with EXISTS
IF Exists (select count(1) from table1)
begin
select * from table1 end else
begin select * from table2 end