How do you filter data using sql query?

Hy all,

thanks before :pray:,

i have db in google sheet, and i want to read the data with sql query,
but how we can filter the unique data with sql query, before the data show in the app,
the sql query is like this,

https://spreadsheet.google.com/tq?tqx=out:csv&key=1blXLcQ_kwLaVOC6eQX5P5Cyze-bUuD8Tip1Adob1Ll4&gid=0&tq=select A

and the result is :

Equipment-Code
EM-Slurry-1
EM-Slurry-1
EM-Slurry-1
EM-Slurry-1
EM-Slurry-1
EM-Slurry-1
EM-Slurry-2
EM-Slurry-2
EM-Slurry-2
EM-Slurry-2
EM-Slurry-2
EM-Slurry-2
can we filter the data before the data read in app,
so the result can be like this:
Equipment-Code
EM-Slurry-1
EM-Slurry-2

many thanks for all.

best regards,

supriyadi

Try the query
SELECT A GROUP BY A
See also Query Language Reference (Version 0.7)  |  Charts  |  Google Developers

Taifun

1 Like

many thanks before,
i try to change the link to this
https://spreadsheet.google.com/tq?tqx=out:csv&key=1blXLcQ_kwLaVOC6eQX5P5Cyze-bUuD8Tip1Adob1Ll4&gid=0&tq=select A group by A
and
https://spreadsheet.google.com/tq?tqx=out:csv&key=1blXLcQ_kwLaVOC6eQX5P5Cyze-bUuD8Tip1Adob1Ll4&gid=0&tq=select A, group by A
but in csv i get this message :
{"version":"0.6","reqId":"0","status":"error","errors":[{"reason":"invalid_query","message":"INVALID_QUERY","detailed_message":"Invalid query: CANNOT_GROUP_WITHOUT_AGG"}]}
how can i fix that . :pray:
thanks,

supriyadi

Try this because

If you don't have an agreggation function (such as sum, avg, count in SELECT), there is no use for GROUP BY (PS: I am not sure but May be)

https://docs.google.com/spreadsheets/u/0/d/1blXLcQ_kwLaVOC6eQX5P5Cyze-bUuD8Tip1Adob1Ll4/gviz/tq?tqx=out:html&gid=0&tq=select%20A%20,%20count(A)%20Group%20by%20A

Result is

1 Like

I have used "max(A) group by A"

1 Like

Like this, hmmmm (always learning from you)

many thanks :pray:

thank you for helping me. :pray:

Try

SELECT MAX(A) GROUP BY A LABEL MAX(A) "Unique Values"

and this returns a row of unique values for A (tested on supplied sheet data)

SELECT MAX(B) PIVOT A LIMIT 0

(both queries tested on supplied sheet data)

wow amazing,
this is very helpful,
thank you very much mr. timaI2.

best regards,

supriyadi