0

Mysql query looks like this

const numOfReplies = await SQL('SELECT COUNT(conversation_id), conversation_id FROM tweet_replies GROUP BY conversation_id')

so there are multiple rows with the same conversation_id, and i want to get a number of rows for every conversation_id. After looping with forEach

numOfReplies.forEach(num => {
  console.log(num)
})

response looks like this

{
  'COUNT(conversation_id)': '10',
  conversation_id: '1530169643423367169'
}
{
  'COUNT(conversation_id)': '10',
  conversation_id: '1530172022357106690'
}

how can i select value of COUNT(conversation_id) from this response?

1 Answer 1

1

Simply name the COUNT value in SQL request with AS keyword and get it like a field :

SELECT COUNT(conversation_id) AS myCount, conversation_id FROM tweet_replies GROUP BY conversation_id

You will get response like this:

{
  myCount: '10',
  conversation_id: '1530169643423367169'
}
{
  myCount: '10',
  conversation_id: '1530172022357106690'
}
Sign up to request clarification or add additional context in comments.

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.