SQL using minus function to eliminate rows from specific columns but returning all columns from table

SCremen525

I'm trying to return all columns in a database where certain rows within certain columns have been eliminate. Is there any possible way to do this? I tried using code like this but I'm unsure what I am missing to make this work

Select * from table1
where (select column1 from table1
minus select column1 from table2);
Siyual

You can do this with a WHERE NOT EXISTS:

Select  T1.*
From    Table1  T1
Where Not Exists
(
    Select  *
    From    Table2  T2
    Where   T2.Column1 = T1.Column1
)

Alternatively, you could use a LEFT OUTER JOIN:

Select      T1.*
From        Table1  T1
Left Join   Table2  T2  On  T2.Column1 = T1.Column1
Where       T2.Column1 Is Null

Or even a WHERE NOT IN:

Select  *
From    Table1
Where   Column1 Not In 
(
    Select  Column1
    From    Table2
)

I would recommend the WHERE NOT EXISTS approach, but to fix the query you have in the question, you just need to add a WHERE IN:

Select  *
From    Table1
Where   Column1 In 
(
    Select  Column1
    From    Table1
    Minus
    Select  Column1
    From    Table2
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Function returning all columns from more than one table (PostgreSQL)

From Dev

Select specific rows and columns from an SQL database

From Dev

Exclude columns from Minus operations in oracle sql

From Dev

Get all columns from an SQL Table without Computed Columns

From Dev

Returning all child nodes as columns from XML in Sql Server

From Dev

Transform a table from rows to columns

From Dev

Transform a table from rows to columns

From Dev

Insert specific rows from one table in database into another with different columns

From Dev

SQL Insert new columns in table B from rows of table A

From Dev

Selecting all rows from Informix table containing some null columns

From Dev

MySQL: Get the MIN value of a table from all columns & rows

From Dev

merge all rows columns into single column from joined table

From Dev

Retrieving data from specific columns of multiple rows in sql

From Dev

SQL, from , separated rows to columns

From Dev

Deleting a specific rows and columns from a data-set using Matlab

From Dev

Finding difference of two columns from two different rows in an SQL table

From Dev

Flatten a SQL Table from rows to columns allowing multiple results

From Dev

SQL Server get rows from table and display in columns

From Dev

leftJoin is returning columns from first table only

From Dev

SQL query optimization for selecting specific columns from a table

From Dev

Fill the columns of a table with data from an specific cell on SQL Server?

From Dev

Eliminate one of the columns from pivot_table for changing the grouping logic

From Dev

How to select all the SQL rows from a table (With a unique combination of two columns) where the same combination is not already in another table

From Dev

Returning a SUM from DISTINCT columns in Microsoft SQL

From Dev

How to extract multiple rows from a table based on values from multiple columns from another table and then concatenate in SQL?

From Dev

Removing specific columns and rows from nested list

From Java

Selecting specific rows and columns from NumPy array

From Dev

Exclude rows with specific columns values from SELECT

From Dev

R: Getting rows from specific columns

Related Related

  1. 1

    Function returning all columns from more than one table (PostgreSQL)

  2. 2

    Select specific rows and columns from an SQL database

  3. 3

    Exclude columns from Minus operations in oracle sql

  4. 4

    Get all columns from an SQL Table without Computed Columns

  5. 5

    Returning all child nodes as columns from XML in Sql Server

  6. 6

    Transform a table from rows to columns

  7. 7

    Transform a table from rows to columns

  8. 8

    Insert specific rows from one table in database into another with different columns

  9. 9

    SQL Insert new columns in table B from rows of table A

  10. 10

    Selecting all rows from Informix table containing some null columns

  11. 11

    MySQL: Get the MIN value of a table from all columns & rows

  12. 12

    merge all rows columns into single column from joined table

  13. 13

    Retrieving data from specific columns of multiple rows in sql

  14. 14

    SQL, from , separated rows to columns

  15. 15

    Deleting a specific rows and columns from a data-set using Matlab

  16. 16

    Finding difference of two columns from two different rows in an SQL table

  17. 17

    Flatten a SQL Table from rows to columns allowing multiple results

  18. 18

    SQL Server get rows from table and display in columns

  19. 19

    leftJoin is returning columns from first table only

  20. 20

    SQL query optimization for selecting specific columns from a table

  21. 21

    Fill the columns of a table with data from an specific cell on SQL Server?

  22. 22

    Eliminate one of the columns from pivot_table for changing the grouping logic

  23. 23

    How to select all the SQL rows from a table (With a unique combination of two columns) where the same combination is not already in another table

  24. 24

    Returning a SUM from DISTINCT columns in Microsoft SQL

  25. 25

    How to extract multiple rows from a table based on values from multiple columns from another table and then concatenate in SQL?

  26. 26

    Removing specific columns and rows from nested list

  27. 27

    Selecting specific rows and columns from NumPy array

  28. 28

    Exclude rows with specific columns values from SELECT

  29. 29

    R: Getting rows from specific columns

HotTag

Archive