0

I have 4 tables named A, B, C, D. I have 2 conditons to get the data

Condition 1

Select *
From A, B, C
Where //All 3 tables are joined with conditions
limit 1; // Display 1 data at a time

Condition 2

Select *
From A, B, D
Where //All 3 tables are joined with conditions
limit 1; // Display 1 data at a time

What I am looking for is to combine above 2 Select Statement such that

If Data Exists in Condition 1 then Display Data OR Display Data from condition 2

How can I acheieve above functionality?

A Indu
  • 25
  • 4

2 Answers2

2

You can do it like this

if exists(/*First query*/)
begin

/*FirstQuery*/

end

else

begin

/*Second Query*/

end
bhunter338
  • 31
  • 3
0

I was thinking of

Select *
From A, B, C
Where //All 3 tables are joined with conditions
limit 1 // Display 1 data at a time
UNION
Select *
From A, B, D
Where not exists(Select *
From A, B, C
Where //All 3 tables are joined with conditions)
limit 1
Cato
  • 3,652
  • 9
  • 12