I know about the exists feature, but that does not help me with the given situation. What I want is:
Check if some row exists, and if exists then check for an another row if row exists.
Here's the sqlFiddle.
Description:
A location table:
| ID | NAME | ADDRESS |
|----|--------|---------|
| 1 | India1 | (null) |
| 2 | India2 | (null) |
| 3 | India3 | (null) |
| 4 | India4 | (null) |
| 5 | India5 | (null) |
Then a location_flag table:
| ID | LOCATION_ID | FLAG_ID | VALUE | PARENT_ID | DELETED |
|----|-------------|---------|-------|-----------|---------|
| 1 | 1 | 1 | YES | (null) | (null) |
| 2 | 1 | 2 | YES | (null) | (null) |
| 3 | 2 | 1 | YES | (null) | (null) |
| 4 | 2 | 2 | NO | (null) | (null) |
What I want is to get all locations except location with id=2.
In procedure, it'd be like:
if(locationWithFlag1='YES'){
if(locationWithFlag2='YES'){
//make this row to be appear in result
}
}
else{
//make this row appear in result
}
Is it possible without bringing in plpgsql?
create table
) show us some sample data (asinsert into ...
) and show us the expected output based on that sample data. Ideally create a sqlfiddle.com examplewhere exists (...) and exists (...)
instead ofnot exists