When I try to run a select statement with subqueries in mysql workbench I encounter an OK response with no results (the query is successful). I am sure the code is alright and mysql also doesn't find any error, but I don't know why I don't get any answer.
Here's the code
SELECT date(created_at),
(SELECT
SUM(amount) AS topup_amount
FROM
wallet_transaction
WHERE
type = 'topup'
GROUP BY DATE(created_at)),
(SELECT
SUM(amount) AS admin_add_amount
FROM
wallet_transaction
WHERE
type = 'admin_add'
GROUP BY DATE(created_at))
FROM
wallet_transaction;
Now, let us return a value if there is no result using the IFNULL method. The query is as follows − +-----------------+ | ResultFound | +-----------------+ | No Result Found | +-----------------+ 1 row in set (0.00 sec) MySQL query to return a string as a result of IF statement? Is there a default ORDER BY value in MySQL?
What happens if MySQL query returns no rows? What happens if MySQL query returns no rows? From the output returned by MySQL, it is very much clear that how many rows are there in the result set along with the execution time. For example, in the following MySQL output we can see there are 3 rows in the result set.
Returning a value even if there is no result in a MySQL query? Returning a value even if there is no result in a MySQL query? You can use IFNULL () function from MySQL to return a value even if there is not result. Let us create a table. Te query to create a table. Insert some records in the table with the help of insert command.
- SQL Server Forum Why Query is not returning any results? First and foremost, the following items are a test of something bigger. The following is a create table script for the tables, cestest and cescode. Followed by a some sample data for both. Lastly, is the query that I am trying to run. I get column headers but no results.
It looks like you are after the result produced by a query like this:
SELECT DATE(wt.created_at) AS dt_created
, IFNULL(SUM(IF(wt.type = 'topup' , wt.amount, 0)),0) AS topup_amount
, IFNULL(SUM(IF(wt.type = 'admin_add', wt.amount, 0)),0) AS admin_add_amount
FROM wallet_transaction wt
GROUP BY DATE(wt.created_at)
There are a couple of issues with the original query. The subqueries in the SELECT list can return at most one row, or MySQL will throw an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With