0

I'll make this post short: I want to count the number of times my row appears in my table where the row is a specific value And another row could be 4 different values. I'll post my "guess" which doesn't work:

SELECT hero_selected, COUNT(hero_type) FROM heroes WHERE hero_type = 'agi' AND hero_selected = 'yt' OR hero_selected = 'yb' OR hero_selected = 'ym' OR hero_selected = 'yf


INFORMATION ABOUT THE TABLE

TABLE NAME
heroes

ROW TO COUNT
hero_type

SELECT "hero_type" WHERE
Value is 'agi'

ONLY SELECT IT WHERE "hero_selected" IS
Either yt, yb, ym or yf

If possible I'd also appreciate the full code including an echo of the count amount in php. Thanks A LOT in advance! :)

1
  • 1
    Is the missing ' at the end a mis-copy? Also, what results do you get opposed to what you expect? Commented Aug 10, 2011 at 0:06

2 Answers 2

5
SELECT COUNT(*) 
FROM heroes 
WHERE hero_type = 'agi' AND hero_selected IN ('yt', 'yb', 'ym', 'yf')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the fast answer! But it's not the complete solution to my problem though. I wanted (maybe hard to get from my explanation) only one number.
0

From what I can glean from your question, you want this query

SELECT COUNT(1) FROM heroes
WHERE hero_type = 'agi'
AND hero_selected IN ('yt', 'yb', 'ym', 'yf')

PHP code might look like this

$db = new PDO(...);
$stmt = $db->query($query);
$count = $stmt->fetchColumn();
echo $count;

I'm assuming here that you only want a single count, not one per different hero_selected value as the other answers are indicating

3 Comments

@Xaade Come again? The question asks for "including an echo of the count amount in php"
Thanks for the fast answer! Worked perfectly, appreciate the help! By the way, just one question: do you guys get anything from helping people here? By that I mean if you can buy stuff for the reputation points or what it's called. If you don't... then you guys are insanely kind!
@Cheezen We get that warm, glowing, warming glow. Also, see stackoverflow.com/faq#reputation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.