Search code examples
mysqlsqlsql-query-store

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.


Solution

  • 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.