Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select NOT IN multiple columns

I need to implement the following query:

SELECT *  FROM   friend  WHERE  ( friend.id1, friend.id2 )           NOT IN (SELECT id1,                          id2                   FROM   likes)  

But NOT IN can't be implemented on multiple columns. How do I write this query?

like image 381
Gunjan Nigam Avatar asked Nov 07 '11 07:11

Gunjan Nigam


People also ask

Can we select column which is not part of GROUP BY?

The direct answer is that you can't. You must select either an aggregate or something that you are grouping by.

How do you select multiple columns not in a row?

To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.

How do I select data from multiple columns?

To select multiple columns from a table, simply separate the column names with commas! For example, this query selects two columns, name and birthdate , from the people table: SELECT name, birthdate FROM people; Sometimes, you may want to select all columns from a table.


1 Answers

I'm not sure whether you think about:

select * from friend f where not exists (     select 1 from likes l where f.id1 = l.id and f.id2 = l.id2 ) 

it works only if id1 is related with id1 and id2 with id2 not both.

like image 153
Michał Powaga Avatar answered Oct 01 '22 09:10

Michał Powaga