Kathia
Kathia

Reputation: 492

Wrong SQL query (beginner)

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

Upvotes: 3

Views: 1595

Answers (2)

sai kiran
sai kiran

Reputation: 557

Add parentheses for tony, example: if u want to check for multiple names ('tony','stark')

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

Upvotes: 1

Rayyan Jawaid
Rayyan Jawaid

Reputation: 88

search IN will use with () round brackets

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

Upvotes: 6

Related Questions