how to execute nested? request in SQL?

Viewed 53

Good day. I have one table. Please help me make a request.

1st request:

SELECT Name, Time FROM table1 WHERE Ongoing_ID IS NOT NULL

2st request:

SELECT Name, Time FROM table1 WHERE Disconnect_ID IS NOT NULL

how can i combine these two queries into one? It is necessary to get values if Ongoing NOT NULL count >0 and Disconnect_ID NOT NULL count >0. Those. I need to get values that both have values. If disconnect_ID = 0, then it is not necessary example sql table:

enter image description here

1 Answers

Easy, use and in the where clause if you want both conditions to be true.

SELECT Name, Time 
FROM
    table1 
WHERE
    Disconnect_ID IS NOT NULL 
    and Ongoing_ID IS NOT NULL

If you want either condition, use or

SELECT Name, Time 
FROM
    table1 
WHERE
    Disconnect_ID IS NOT NULL 
    or Ongoing_ID IS NOT NULL

Edit based on comment

SELECT Name, Time 
FROM
    table1 
WHERE
    Disconnect_ID > 0
    and Ongoing_ID > 0
Related