Dan
Dan

Reputation: 1

SQL - Alternative to WHERE AND/OR clauses

I'm a beginner and I have basic knowledge on the matter, so i apoligize if i couldn't find the right answer. Here's the code I've written. It returns exactly what I need but I feel like it's not a great solution, any suggestions? I'm working on Oracle SQL Developer. Thanks in advance

SELECT
    ta.id,
    tb.taid,
    tc.idb,
    ta.durata,
    tc.durata,
    tb.durata,
    ta.data_attivazione,
    ta.data_disattivazione,
    tc.data_inizio,
    tc.data_fine,
    tb.data_inizio,
    tb.data_fine
FROM
    tableA ta
    tableB ta
    tableC tc
WHERE
    ta.id = 3456
    AND tb.taid = 3456
    AND tc.idb = 3456
    OR (
        ta.id = 3457
        AND tb.taid = 3457
        AND tc.idb = 3457
    )

Upvotes: 0

Views: 178

Answers (3)

You could use the join to simplify your code:

enter image description here

Upvotes: -1

Gordon Linoff
Gordon Linoff

Reputation: 1270463

Use proper, explicit, standard JOIN syntax:

select . . .
from tableA ta join
     tableB tb
     on ta.id = tb.taid join
     tableC tc
     on tc.idb = ta.id
where ta.id in (3456, 3457)

Upvotes: 4

Jens
Jens

Reputation: 69470

Use join:

SELECT
    ta.id,
    tb.taid,
    tc.idb,
    ta.durata,
    tc.durata,
    tb.durata,
    ta.data_attivazione,
    ta.data_disattivazione,
    tc.data_inizio,
    tc.data_fine,
    tb.data_inizio,
    tb.data_fine
FROM
    tableA ta join tableB tb on ta.id= tb.taid
    join tableC tc on tb.taid = tc.idb
WHERE
    ta.id in (3456, 3457)

Upvotes: 3

Related Questions