Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong SQL query (beginner)

Tags:

sql

mysql

I am new in SQL, and I am learning alone on Udemy. I came across multiple questions, and I am struggling with one of them:

What is wrong with this SQL query?

SELECT sport, count(*) 
FROM activities 
WHERE username IN ‘tony’
GROUP BY 1;

I have two hypothesis: 1 - If the field 'sport' in activities is filled with string values, then we can't use count. 2 - the last statement should be rather:

WHERE username in:‘tony’ GROUP BY 1;

I would be happy to have your feedback on the question and learn from you! Thanks

like image 368
Kathia Avatar asked Jul 04 '26 02:07

Kathia


1 Answers

search IN will use with () round brackets

SELECT sport, count(*) 
FROM activities 
WHERE username IN ('tony')
GROUP BY 1;
like image 103
Rayyan Jawaid Avatar answered Jul 06 '26 15:07

Rayyan Jawaid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!