Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql returning OK but with no results

Tags:

mysql

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;
like image 943
s_ehsan_g Avatar asked May 14 '16 20:05

s_ehsan_g


People also ask

How to return a value if there is no result in MySQL?

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

How to return a value even if there is no result?

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.

Why is my query not returning any results?

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


Video Answer


1 Answers

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.

like image 172
spencer7593 Avatar answered Oct 21 '22 04:10

spencer7593