简体   繁体   中英

MYSQL/PHP Get values from JOIN of same column name

SELECT admin.User, a.time

FROM admin 

LEFT JOIN a ON admin.User=a.User

LEFT JOIN b ON admin.User=a.User

So I have three tables, admin then a & b. At the moment I get tables a & b by joining via a shared field called User. However tables a & b have a field called 'types' which is not in the admin table.

What I want to do is instead of select 'types' twice - once for table a and once for table b, is have the 'types' field combined so there is only one results set for that field.

try to use ifnull(a.types, b.types) as types to export the field. (MySQL)

so that it try to get a.types first, if that yields null, then yields b.types instead.

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