Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL Logical ALL

I’m trying to get a Logical ALL function working, but can’t figure out the syntax.

I already have a boolean column in my data, and I’m trying to aggregate by some other column using a Logical ALL.

If my data is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

category value
A 1
A 1
A 1
B 0
B 0
B 1
C 0
C 0
C 1

My expected output is:

category ALL(value)
A 1
B 0
C 0

My naive attempt was:

SELECT category, ALL(value) FROM table
GROUP BY category;

Which gives a syntax error.

>Solution :

Using BIT_AND:

SELECT category, BIT_AND(value) FROM tab GROUP BY category; 

db<>fiddle demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading