r/learnSQL • • 9h ago

Quick SQL puzzle. Why does this LEFT JOIN lose the customer with no orders?

1 Upvotes

There are two customers. Customer 1 has one paid order. Customer 2 has no orders.

I want both customers in the result, with paid order details where available.

SELECT c.id, o.status

FROM customers AS c

LEFT JOIN orders AS o

ON c.id = o.customer_id

WHERE o.status = 'paid';

This only returns customer 1. My first instinct would be to look at the join, but the row actually disappears because of the WHERE clause.

The fix here is to move o.status = 'paid' into the ON condition and remove the WHERE clause. That way the join looks for a paid order, and customer 2 still shows up with NULL for status.


r/learnSQL • • 19h ago

How to fix a error 1100?

3 Upvotes

SQL Error [1100]: Query execution failed: INVALID_FUNCTION_ARGUMENT: Invalid format: "01/07/2026" is malformed at "/07/2026"

Query execution failed: INVALID_FUNCTION_ARGUMENT: Invalid format: "01/07/2026" is malformed at "/07/2026"

INVALID_FUNCTION_ARGUMENT: Invalid format: "01/07/2026" is malformed at "/07/2026"

AI Aint helping


r/learnSQL • • 2h ago

How to learn postgresql

4 Upvotes

Did learning express. so as next step in thinking of learning postgresql instead of mongodb. so how. how did you learn. my stack is pern and is it good??


r/learnSQL • • 5h ago

Which books worked best for you?

8 Upvotes

I know this is potentially an FAQ and the common answer will be to point me to a website or a course but I’m in a bit of a tricky situation in that I need to learn SQL for my job but my employer will only fund books rather than courses so I was wondering which books worked best for you guys? Thanks.