q icon indicating copy to clipboard operation
q copied to clipboard

Question - can I join multiple CSV tables

Open avnerbarr opened this issue 6 years ago • 1 comments

I want to compare values from 2 seperate csv files , for instance a trivial query like this , but I get an error that the column doesn't exist

q "select * from /tmp/1.csv as a inner join /tmp/2.csv as b where a.sku=b.sku" -d "," 
query error: no such column: a.sku

If I change to a different column the result seems to be returned

 q "select * from /tmp/1.csv as a inner join /tmp/2.csv as b where a.c1=b.c1" -d "," 
sku,c1,c2,sku,c1,c2,c3
a,b,c,a,b,c,d
c,d,e,c,e,e,f
d,e,f,d,e,f,g

avnerbarr avatar Oct 19 '17 09:10 avnerbarr

If i'm not missing something, then you need to add -H to the command line so the header row will be used to name the columns. If i'm missing something, please send the first few rows of the two files as an example, or some small dummy data, so i can understand the issue better.

You can also run the query using -A - This will analyze the data and show you the resulting "table" structure that q has determined, along with column names and types.

harelba avatar Oct 19 '17 09:10 harelba