简体   繁体   中英

How to use multiple Select statement in MySQL

Lets say i want to select (total Number of Customer from Customer table), as well as (Total Sum of transaction Amount from transaction Table).

I want to list out both result in single query..

select Count(id) from Customer
select Sum(Amount) from Transactions

Please help me to to do.

You can put the two queries in subqueries:

SELECT (SELECT COUNT(*) FROM Customer) AS customers,
       (SELECT SUM(amount) FROM Transactions) AS amount
FROM DUAL

You don't need FROM DUAL if you're doing this in MySQL, you may need it in other databases.

You can use join statement to join both table and get data from each table. For join statement refer this link or you can use

SELECT t1.*,t2.* FROM t1,t2

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