I have always done inner joins that look like this
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
Where you specify each row you want. I am currently working with a table that has 50 rows however and I don't want to type all these SQL joins with all the rows, is there a way to say "select * from Orders, then give me Customers.CustomerName join on ...." instead of specifying every row from the first table?
SELECT Orders.*, Customers.CustomerName
You simply define what you want via tablename.column
so you can either specify an existing column name, or use star *
to indicate all columns from that table.
In applications it's highly recommended to be explicit about columns you want to select and to avoid *
, but if you are running these queries for yourself it makes sense to use it:
SELECT table_name.*
Note that you can also omit the qualifying table name from the column if the column name is unique. That is Customers.CustomerName
can just be CustomerName
unless Orders
also has a CustomerName
column. In the same vein, Orders.OrderID
can just be OrderID
.
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