Skip to content

The result of query ends up with 'null' values with keywords: ORDER BY and LIMIT #1965

@daviddabingu

Description

@daviddabingu

I've been trying to build this test app where user uploads csv file and then run SQL queries.
This is the SQL query.

SELECT [subcategoryname], SUM([totalamount]) AS sales
FROM temptable
GROUP BY [subcategoryname]
ORDER BY sales DESC
LIMIT 3

UNION ALL

SELECT [subcategoryname], SUM([totalamount]) AS sales
FROM temptable
GROUP BY [subcategoryname]
ORDER BY sales ASC
LIMIT 3;

As you can see here, what I tried to do was to get top/bottom 3 of SUM([[totalamount]) from the table, using UNION ALL.
However, what I've got returned follows: only three rows, where 2 containing 'null' sales value.
My assumption here was that ORDER BY somehow includes null values when sorting.

image


AlaSQL is based on unpaid voluntary work. Thank you for taking the time to make it better.

Got ChatGPT?


Question about how to...


Something is not working as expected:

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions