Minus clause in oracle used to query the records which are exists in table1 but not in table2.
select * from table1
minus
select * from table 2
or
select column1, column2... from table1
minus
select column1, column2... from table2
Make sure the data types for the columns should be compatible.
For example Table1 and table2 as below
select name, loc from table1
minus
select name, loca from table2
will result as below
Kishore nyc
Vihaan saf
Same MINUS clause in SQL Server corresponds to EXCEPT command
Here the syntax is
select * from table1
except
select * from table 2
or
select column1, column2... from table1
except
select column1, column2... from table2
However in MySQL we are not having any direct minus or except clause.
select * from table1 where (column1, column2) not in ( select * from table2);
or
select * from table1
minus
select * from table 2
or
select column1, column2... from table1
minus
select column1, column2... from table2
Make sure the data types for the columns should be compatible.
For example Table1 and table2 as below
![]() |
Table 1 and Table 2 |
minus
select name, loca from table2
will result as below
Kishore nyc
Vihaan saf
Same MINUS clause in SQL Server corresponds to EXCEPT command
Here the syntax is
select * from table1
except
select * from table 2
or
select column1, column2... from table1
except
select column1, column2... from table2
However in MySQL we are not having any direct minus or except clause.
select * from table1 where (column1, column2) not in ( select * from table2);
or
select * from table1 where not exists ( select * from table2 where table2.x=table1.x and table2.y=table1.y)
or
SELECT t1.col1, t1.col2
FROM table1 t1 LEFT JOIN table2 t2
ON t.col1 = t2.col1 AND t1.col2 = t2.col2
WHERE t2.col1 IS NULL;
No comments:
Post a Comment