Use Star (*) with mysql inner join?

I always did internal joins like this

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID; 

Here you specify each line you need. I am currently working with a table that has 50 rows, and I don’t want to enter all these SQL connections with all rows, is there any way to say β€œselect” from β€œOrders” and then give me the name Client.CustomerName. ... "instead of specifying each row from the first table?

+4
source share
2 answers
 SELECT Orders.*, Customers.CustomerName 

You simply specify what you want through tablename.column so you can specify an existing column name or use an asterisk * to indicate all columns from this table.

+8
source

In applications, it is strongly recommended that you clearly indicate the columns that you want to select and avoid * , but if you use these queries for yourself, it makes sense to use it:

 SELECT table_name.* 

Note that you can also omit the qualification table name from a column if the column name is unique. That is, Customers.CustomerName can simply be CustomerName if Orders also does not have a CustomerName column. In the same vein, Orders.OrderID can only be OrderID .

+1
source

Source: https://habr.com/ru/post/1498413/


All Articles