The "SQL" Parameter

Fine tune your data output in line with this parameter

The SQL url parameter (?sql=) can be used to filter, sort or group the data export. Below are examples of how it can be used to restructure your data.

Example Export URL

https://api.csvgetter.com/AADVgE0BE2k04FgjZJtX

Output (CSV)

Name,Age,Gender,Occupation
John Doe,35,Male,Engineer
Jane Smith,28,Female,Doctor
Michael Johnson,42,Male,Teacher
Emily Brown,31,Female,Software Developer
David Wilson,45,Male,Manager

Limit records

?sql=select * from csvgetter limit 1 (if first parameter)

&sql=select * from csvgetter limit 1 (if not first parameter)

What does it do?

Only shows the first row of data. (To show the first n rows change to limit n)

Example

https://api.csvgetter.com/AADVgE0BE2k04FgjZJtX?sql=select * from csvgetter limit 1

Name,Age,Gender,Occupation
John Doe,35,Male,Engineer

Filter records

?sql=select * from csvgetter where <column_name>='<value>' (if first parameter)

&sql=select * from csvgetter where <column_name>='<value>' (if not first parameter)

What does it do?

Only shows data where <column_name> is equal to <value>.

Example

https://api.csvgetter.com/AADVgE0BE2k04FgjZJtX?sql=select * from csvgetter where Occupation='Teacher'

Name,Age,Gender,Occupation
Michael Johnson,42,Male,Teacher

Sort records by Column

Ascending

?sql=select * from csvgetter order by <column_name> asc (if first parameter)

&sql=select * from csvgetter order by <column_name) asc (if not first parameter)

Descending

?sql=select * from csvgetter order by <column_name> desc (if first parameter)

&sql=select * from csvgetter order by <column_name) desc (if not first parameter)

What does it do?

Orders the data by the selected column name

Example

https://api.csvgetter.com/AADVgE0BE2k04FgjZJtX?sql=select * from csvgetter order by Age asc

Name,Age,Gender,Occupation
Jane Smith,28,Female,Doctor
Emily Brown,31,Female,Software Developer
John Doe,35,Male,Engineer
Michael Johnson,42,Male,Teacher
David Wilson,45,Male,Manager

Group records by column

?sql=select Gender, count(*) as 'Number of records' from csvgetter group by Gender (if first parameter)

&sql=select Gender, count(*) as 'Number of records' from csvgetter group by Gender (if not first parameter)

What does it do?

Groups the records by gender, counts the number of records that matches each gender.

Example

https://api.csvgetter.com/AADVgE0BE2k04FgjZJtX?sql=select Gender, count(*) as 'Number of records' from csvgetter group by Gender

Gender,Number of records
Female,2
Male,3

With our encoder tool:

select Gender, count(*) as 'Number of records' from csvgetter group by Gender

becomes...

select%20Gender%2C%20count(*)%20as%20'Number%20of%20records'%20from%20csvgetter%20group%20by%20Gender

and can be used like:

https://api.csvgetter.com/AADVgE0BE2k04FgjZJtX?sql=select%20Gender%2C%20count(*)%20as%20'Number%20of%20records'%20from%20csvgetter%20group%20by%20Gender

Generally speaking, CSV Getter API can accept any read-only (SELECT) SQL statements. Think of any other cool SQL to include in this page? Let us know!

FAQs

Is my CSV data liable to SQL injection?

No. We have designed the system such that SQL only works read-only, and does not interact with the underlying data.

Last updated