Order by in Inner Join

后端 未结 6 951
难免孤独
难免孤独 2021-02-18 16:28

I am putting inner join in my query.I have got the result but didn\'t know that how the data is coming in output.Can anyone tell me that how the Inner join matching the data.Bel

6条回答
  •  一个人的身影
    2021-02-18 17:23

    Avoid SELECT * in your main query.

    Avoid duplicate columns: the JOIN condition ensures One.One_Name and two.One_Name will be equal therefore you don't need to return both in the SELECT clause.

    Avoid duplicate column names: rename One.ID and Two.ID using 'aliases'.

    Add an ORDER BY clause using the column names ('alises' where applicable) from the SELECT clause.

    Suggested re-write:

    SELECT T1.ID AS One_ID, T1.One_Name, 
           T2.ID AS Two_ID, T2.Two_name
      FROM One AS T1
           INNER JOIN two AS T2
              ON T1.One_Name = T2.One_Name
     ORDER 
        BY One_ID;
    

提交回复
热议问题