E
E
Evgeny Antipov2018-05-25 15:52:29
MySQL
Evgeny Antipov, 2018-05-25 15:52:29

MYSQL LEFT JOIN returns NULL on empty table?

How? Why? The tables are empty.

SELECT 
    st.*, MAX(sp.date) as last_date,
    SUM(case when sp.user_id != 3 then sp.status end) as unread 
FROM support_ticket st 
LEFT JOIN support_message sp ON sp.ticket_id = st.id 
WHERE st.user_id = 3

Execution result
ROW COUNT (1)
+-----------------------------------------------------------------------------------------------------------------+
|   id    | user_id  |  title  | service | type  | express | status | open_date | close_date | last_date | unread |
+-----------------------------------------------------------------------------------------------------------------+
|   NULL  |  NULL    |   NULL  |   NULL  | NULL  |   NULL  | NULL   |   NULL    | NULL       | NULL      | NULL   |
+-----------------------------------------------------------------------------------------------------------------+

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2018-05-25
@elevennine

Returns an error, an error.
And when ONLY_FULL_GROUP_BY is off, it will return any nonsense.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question