Mohamed Shahid
Mohamed Shahid

Reputation: 475

How to find set difference in Mysql?

What is the 'except' equivalent command in mysql?

SELECT name FROM table1 except SELECT name FROM table2

Upvotes: 0

Views: 2241

Answers (3)

Anju Augustin
Anju Augustin

Reputation: 47

This query will work for your scenario:

select A.* 
from
(SELECT name FROM table1) A,
((SELECT name FROM table1) B
where
A.name != B.name;

Upvotes: 0

Kickstart
Kickstart

Reputation: 21533

Often easiest to use a LEFT OUTER JOIN, and then in the WHERE clause check that there is no matching field.

SELECT name 
FROM table1 
LEFT OUTER JOIN table2 ON table1.name = table2.name
WHERE table2.name IS NULL

Upvotes: 0

dsharew
dsharew

Reputation: 10675

As mentioned by @Lelio Faieta: Phpmyadmin is just a tool to access and operate on mysql database.

But if you want to achieve the "except" concept try like this:

SELECT name FROM table1 where name NOT IN( SELECT name FROM table2)

This will give you names in table1 that are not in table2.

Upvotes: 2

Related Questions