简体   繁体   中英

how to combine two select query in one query

SELECT users.firstname from users
INNER JOIN user_ps
ON user_ps.user_id=users.id where user_id=23 group BY user_ps.user_id

SELECT SUM(best + better + good) from user_ps as total where user_id=23

Hi I'm new user I need help here how can you combine both in one query please help me out

You can combine it using union

SELECT users.firstname from users
INNER JOIN user_ps
ON user_ps.user_id=users.id where user_id=23 group BY user_ps.user_id
UNION
SELECT SUM(best + better + good) from user_ps as total where user_id=23

Try this:-

SELECT users.firstname, SUM(best + better + good) AS Total
FROM users INNER JOIN user_ps
ON user_ps.user_id=users.id 
WHERE user_id=23 
GROUP BY users.firstname;

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