How can I select a data from another column from rows that have been selected?

Jason

I tried my best to figure and google this out, but couldn't really find a solid answer to it.

The problem I'm facing is that

Table 1:

ID    Value 1
1     a
2     b
3     c

Table 2:
ID    Value 2
1     4a
3     5b
4     6c

and I'd basically have to select the value from Table 1 that doesn't exist on Table 2 (Thus, 'b')

I can select and identify the ID that I want by using minus function between the tables, but can't seem to figure out a way to call a query to instead call the data.

Littlefoot

Use the MINUS as a subquery (i.e. an inline view) (lines #14 - 16):

Sample data:

SQL> with
  2  table1(id, value1) as
  3    (select 1, 'a' from dual union all
  4     select 2, 'b' from dual union all
  5     select 3, 'c' from dual
  6    ),
  7  table2 (id, value2) as
  8    (select 1, '4a' from dual union all
  9     select 3, '5b' from dual union all
 10     select 4, '6c' from dual
 11    )

Query begins here:

 12  select a.*
 13  from table1 a
 14  where a.id in (select t1.id from table1 t1
 15                 minus
 16                 select t2.id from table2 t2
 17                );

        ID VALUE1
---------- ----------
         2 b

SQL>

Alternatively, use not exists:

<snip>
 12  select a.*
 13  from table1 a
 14  where not exists (select null
 15                    from table2 b
 16                    where b.id = a.id
 17                   );

        ID VALUE1
---------- ----------
         2 b

SQL>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I average every 5 rows specific column and select last data from another column in Pandas

How can I put a textbox inside a table data which rows have been appended/moved from another table?

How do I both randomly select rows from a data frame and delete each row as it has been selected?

How to conditionally select a column, and subtract values in those rows from rows in another conditionally selected column in R?

How to remove a selected option from another select tag when i have five select with same options and values?

In R, how do I match values from selected rows in one data frame with selected columns in another?

Select data from one table based on selected rows in another

How can I fetch rows from a table that have been created or modified in the last two days?

How do I collect value from a column base on it's row data selected in another column?

How can I make sure that two rows selected at random are different from one another?

In Excel, how can I filter, pull, and sum values from a column if their rows match data in another table and are within a specific date range?

How do I remove specified rows from a data frame in R, but the rows are eliminated according to another column variable?

How to collect data for the rows that have been selected in AngularJS?

How can i order my rows from (first) a column and then (secondly) another column which is a specific starting time?

How can I drop consecutive duplicate rows in one column based on condition/grouping from another column?

How can I subset a dataframe to rows relative to column values from another inside a function where that column is a parameter?

Select another column from rows that match a filter and then delete based on the new selected column in R

How can I pass an object selected by the user, to another view and retrieve a specific column from that object?

Divide values from selected rows from one column by another column

Spreadsheet - I want to append data from one sheet to another, they only have one column that can be used as a reference

how to select rows in pandas dataframe based on between from another column

How do I get the selected value from the select to another component?

How can I select distinct column combinations from a DataTable object with another column as a condition?

Laravel Raw Statement Where I can select from different table based on if a column data is equal to another

How can I select rows of a data frames if column is a list?

How can I make a select count(*) with where clause from another table return empty rows?

How can I group rows by most recent previous date from a column in another table?

How can I filter rows which contains 2 or more words from another column?

How can I remove the rows that matches from one Excel column with another Excel file? With VBA