I need to make a query like this:
SELECT table1.*, table2.column
FROM table1
LEFT JOIN table2 ON table1.column = table2.column
But it's not working. If I try the same query but replacing the first part -- >
SELECT table1.column, table2.column
FROM table1
LEFT JOIN table2 ON table1.column = table2.column
it works fine. I need to bring all the columns from table1. How can I make it without specifing all of them?
Introduction to SQLite LEFT JOIN clause Similar to the INNER JOIN clause, the LEFT JOIN clause is an optional clause of the SELECT statement. You use the LEFT JOIN clause to query data from multiple related tables.
Unfortunately, SQLite does not support the RIGHT JOIN clause and also the FULL OUTER JOIN clause. However, you can easily emulate the FULL OUTER JOIN by using the LEFT JOIN clause.
To query data from both artists and albums tables, you use can use an INNER JOIN , LEFT JOIN , or CROSS JOIN clause. Each join clause determines how SQLite uses data from one table to match with rows in another table. Note that SQLite doesn't directly support the RIGHT JOIN and FULL OUTER JOIN .
In SQLite, the INNER JOIN selects all rows from both participating tables to appear in the result if and only if both tables meet the conditions specified in the ON clause. JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents. In standard SQL, they are not equivalent.
If you have the same column name in table1
and table2
, here is the solution for not specifying all the column name of table1
:
SELECT table1.*, table2.column as my_column_name_no_in_table1
FROM table1
LEFT JOIN table2 ON table1.column = table2.column
If the column names of table1
and table2
are all different, you can use :
SELECT table1.*, table2.*
FROM table1
LEFT JOIN table2 ON table1.column = table2.column
But as said in the peterm's comment, it is not a good practice in production. Now, do as you want! ;)
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