INNER JOIN same table

后端 未结 6 759
盖世英雄少女心
盖世英雄少女心 2021-01-01 11:32

I am trying to get some rows from the same table. It\'s a user table: user has user_id and user_parent_id.

I need to get the user_id

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 12:22

    Your query should work fine, but you have to use the alias parent to show the values of the parent table like this:

    select 
      CONCAT(user.user_fname, ' ', user.user_lname) AS 'User Name',
      CONCAT(parent.user_fname, ' ', parent.user_lname) AS 'Parent Name'
    from users as user
    inner join users as parent on parent.user_parent_id = user.user_id
    where user.user_id = $_GET[id];
    

提交回复
热议问题