简体   繁体   中英

retrieve data from two columns with the same name but different table

I want to be able to select the column from users and dusers. example:

select u.user, d.user FROM users u JOIN dusers .... etc.

...like so:

echo $row['u.user']

echo $row['d.user']

I tried this, but no go. How do I specify what table to retrieve the user from?

Alias the columns in the select clause:

select u.user AS u_user, d.user AS d_user ....

then you can use:

echo $row['u_user']  
echo $row['d_user']  
SELECT
    u.user AS u_user,
    d.user AS d_user
FROM users u JOIN dusers

Then:

echo $row['u_user'];
echo $row['d_user'];

Use the "AS" sql attribute.

select u.user AS uuser, d.user AS duser FROM users u JOIN dusers ...

And the array will be the following :

echo $row['uuser']
echo $row['duser']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM