Why a SQL Query Returns No Rows
An empty result is almost always a filter that does not match the real data: case, ranges, or AND/OR.
The symptom
The query runs without error but comes back empty, even though you're sure matching rows exist.
The usual causes
| Cause | Example |
|---|---|
| Case mismatch (text is case-sensitive) | status = 'Shipped' when the data is 'shipped' |
| A NULL comparison | coupon_code = null instead of is null |
| An impossible AND | where state = 'PA' and state = 'CA' |
| A date range that excludes everything | End date before the start date |
How to debug it
Strip the query back and inspect the real values, then add conditions one at a time until the rows disappear. That last condition is your culprit.
Case is the classic culprit: a text comparison is exact, so your filter has to match the stored value letter for letter.
select order_id, status
from orders
where status = 'Shipped'
order by order_idselect order_id, status
from orders
where status = 'shipped'
order by order_idWhen a SQL view returns no rows
Debug a view the same way you debug a query: start with the base table, then add each join and filter back one at a time. For an exact text filter such as where coupon_code = 'spring10', first prove that value exists in the real data with the same casing and spacing:select distinct coupon_code from orders shows that Garden Shop stores those codes uppercase, so that filter finds nothing.
To compare text without worrying about case, lowercase both sides:lower(status) = 'shipped'.