Skip to content
Advertisement

Add subquery in query – Oracle SQL

My query return all days in month.

How get all days from query where DAY_ID not in ==> (Select day_id from table1)

Eg. table1 return 5,10,15

Query resault need to display all days except 5,10,15

Advertisement

Answer

You can generate your calendar and then use NOT EXISTS:

Which, for your sample data:

Outputs:

DAY DAY_ID
1 MON 1
2 TUE 2
3 WED 3
4 THU 4
6 SAT 6
7 SUN 7
8 MON 8
9 TUE 9
11 THU 11
12 FRI 12
13 SAT 13
14 SUN 14
16 TUE 16
17 WED 17
18 THU 18
19 FRI 19
20 SAT 20
21 SUN 21
22 MON 22
23 TUE 23
24 WED 24
25 THU 25
26 FRI 26
27 SAT 27
28 SUN 28

db<>fiddle here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement