Home > other >  How to access query result with the selection as object name
How to access query result with the selection as object name

Time:05-15

I have made a query on a data and it returns a result: [ RowDataPacket { 'COUNT(t.id)': 2 } ]

How can I access it like the count number? I have tried result.COUNT(t.id) but it isn't worked.

CodePudding user response:

The way the object is named, you need to access it like so:

result[0]["COUNT(t.id)"]

I would rather name the columns explicitly by using aliases in the query:

select count(t.id) as count_of_id
from ...
  • Related