I've two tables in SQLite:
Table1:
-------
id
name
Table2:
-------
id
temp_name
My question is, how do I write an SQL query that returns names in Table2
that are not in Table1
?
For example:
Table1:
-------
1, 'john'
2, 'boda',
3, 'cydo',
4, 'linus'
Table2:
-------
1123, 'boda'
2992, 'andy',
9331, 'sille',
2, 'cydo'
In this example the SQL query should return elements andy
, and sille
from Table2
, because they're not in Table1
.
How to Select All Records from One Table That Do Not Exist in Another Table in SQL? We can get the records in one table that doesn't exist in another table by using NOT IN or NOT EXISTS with the subqueries including the other table in the subqueries.
select [ selecting columns] From table1 Right OUTER JOIN table2 ON(table1. SQL> select e. select [ selecting columns] From table1 Right OUTER JOIN table2 ON(table1. select column_name from table 1 full outer join table 2 on(connection); here all the data from table 1 and table 2 will get retrieved.
To select data from an SQLite database, use the SELECT statement. When you use this statement, you specify which table/s to select data from, as well as the columns to return from the query. You can also provide extra criteria to further narrow down the data that is returned.
To query data from multiple tables, you use INNER JOIN clause. The INNER JOIN clause combines columns from correlated tables.
This is how to do it in "obvious" standard SQL:
select *
from table2
where temp_name not in (select name from table1)
There are other methods, such as using left outer join
, exists
in the where
clause, and the except
operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With