'How to query this in Mysql? I need to get the numbers

my table consist of 2 columns

first_id second_id
1 2
1 3
1 4
2 3

What is the query to get the following values?

first_id second_id
1 3
1 4

so I just want the 1,2 and 2,3 pairs excluded from the result?



Solution 1:[1]

Here's an example and the query:

create table test (first_id int, second_id int);
insert into test values (1, 2), (1, 3), (1, 4), (2, 3);

Query:

select *
from test where not
( 
  (first_id = 1 and second_id = 2)
  or
  (first_id = 2 and second_id = 3)
);

Result:

first_id | second_id
-------: | --------:
       1 |         3
       1 |         4

Example

https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=708aae05c61a533a9278dc1e4b2e89ac

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zedfoxus