2

When I run a query like,

SELECT item, COUNT(*) FROM table WHERE item IN (1,2) GROUP BY item;

I get back an normal array with the objects returned, but I can't access the COUNT(*) value with a normal operation such as

result[0].COUNT(*)

as I would normally do result[0].item

How am I supposed to access this item? I tried to search for it around, but I only found solutions for PHP. Thanks

0

3 Answers 3

3

Name your aggregate column in your query

SELECT item, COUNT(*) as [count] FROM table WHERE item IN (1,2) GROUP BY item;

and access it as a column

result[0].count
Sign up to request clarification or add additional context in comments.

Comments

3

Try this SQL:

SELECT item, COUNT(*) AS count FROM table WHERE item IN (1,2) GROUP BY item;

Then in your javascript you can do: result[0].count

Comments

2

If it's a naming issue, then rename the column like this

count(*) as count

then access it as before with result[0].count

Comments

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.