MYSQL using AND in a group using an operator instead of commas

What is the difference between using AND

SELECT 
    id, text
FROM
    table
GROUP BY id and text

And using a comma ,

SELECT 
    id, text
FROM
    table
GROUP BY id, text

It connects together if they have one of the elements.

IE

a,a
a,b
b,b
b,b
x,z

using ANDreturns

a,a
x,z

using ,returns

a,a
a,b
b,b
x,z

What is the purpose of this and why can it be used?

+4
source share
2 answers

What an interesting question ...

So, after some study (both internal research, which brings deep cathartic satisfaction, and the study of Google documentation for MySQL) and testing, I can help you with this:

'AND' - , . 'id AND text' - . , . , :

select (id AND text),id,text from table

GROUP BY

GROUP BY . GROUP BY example, .

, 'Group By id,text', , b, b.

"id AND text", , , TRUE FALSE. , TRUE FALSE. , (id AND text), , .

GROUP BY x y , . GROUP BY x, y AGGREGATE .

+3

AND . TRUE (1), TRUE. FALSE (0), FALSE. , . GROUP BY id AND text , (TRUE FALSE).

.

:

SELECT 
    CASE WHEN (u.conditions_accepted AND u.payment_made)
        THEN 'valid users'
        ELSE 'not valid users'
    END AS `group`,
    COUNT(u.user_id) AS num_users
FROM users u
GROUP BY (u.conditions_accepted AND u.payment_made)
+3

All Articles