SQL Query help

hello there,

i have this query which i get correct data.now i want to know can i change this query to iterate co_id from 1 to the last co_id and return all the values.rather me entering co_id for each of the co_id in the table.

Select a.NAME, count( b.TERMINAL_ID) AS Value
                  from Portal_State a
                  join Terminal_Ports b on a.STATE_ID = b.PORTAL_STATE_ID
                  join Terminals c on b.TERMINAL_ID = c.TERMINAL_ID
                  and CO_ID = 2
                  group by a.STATE_ID, a.NAME
                  order by STATE_ID
zolfAsked:
Who is Participating?
 
appariConnect With a Mentor Commented:
try

Select CO_ID , a.NAME, count( b.TERMINAL_ID) AS Value
                  from Portal_State a
                  join Terminal_Ports b on a.STATE_ID = b.PORTAL_STATE_ID
                  join Terminals c on b.TERMINAL_ID = c.TERMINAL_ID
                  group by CO_ID , a.STATE_ID, a.NAME
                  order by STATE_ID
0
 
Jai STech ArchCommented:
just remove teh CO_ID checking from your query

Select a.NAME, count( b.TERMINAL_ID) AS Value
                  from Portal_State a
                  join Terminal_Ports b on a.STATE_ID = b.PORTAL_STATE_ID
                  join Terminals c on b.TERMINAL_ID = c.TERMINAL_ID
                  group by a.STATE_ID, a.NAME
                  order by STATE_ID
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.