cancel
Showing results for 
Search instead for 
Did you mean: 

Count Rows over lists of tables

Ben_R
New Contributor
Hi, i have a variable where each item is a table.  How can i return a list of their number of rows.  For example:

a,b,c,d are tables with # of rows 1,2,9,10 respectively

y: `a`b`c`d

z: select count i for each table in y

z:1 2 9 10

y join z
a 1
b 2
c 9
d 10

thanks


3 REPLIES 3

jwbuitenhuis
New Contributor

exec gives you the query result as a list, if you know there will be only one you can run 'first exec':


y:{([]n:x?100)}each 1 2 9 10

{first exec count i from x}each y


or 


`a`b`c`d!{first exec count i from x}each y


does that help at all?


miketurk86
New Contributor
If the tables are stored in the variable y, then you may use

y!count each value each y

To create a dictionary of the table names and their respective number of rows.

Flying
New Contributor III
q)a:([]a:10?10.;b:10?`3)
q)b:([]a:3?10.;b:3?`3)
q)c:([]a:12?10.;b:12?`3)
q)t:`a`b`c
q)t!(count value@)each t
a| 10
b| 3
c| 12