简体   繁体   中英

How to Alter MySQL Query to Temporarily Change Column Name

I have the following SQL query:

SELECT p.id, title, l.id, username FROM photoTable p JOIN userTable l ON (l.id = p.iduser) ORDER BY p.id DESC LIMIT 50

I need to change the p.id to p.IdPhoto but the problem is that I only want this done temporarily within the call. I have seen ALTER TABLE as an option, but I am a bit unsure of how I can do this without altering both id fields. Any ideas?

Would this work?

SELECT p.id as idPhoto, title, l.id, 
username 
FROM photoTable p 
JOIN userTable l ON (l.id = p.iduser) 
ORDER BY p.id DESC LIMIT 50

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