Query for Limited Columns and Limited Data Points


I am trying to create a query that will only grab several columns (specified by me) and only limited data points, like, for example, last 10 or 20 entries, last 30 days entries or all entries from the current month.

I created a query that grabs the entire table from Google Sheets, and it is called query_1.

Below is my new query but it does not work. I need 2 versions: the front end users can select data range and the hidden data range that simply shows them data for the last 30 days.

Also, the query should update automatically (it is linked to Google Sheets).

What am I doing wrong?

To do this you need two data sources.

  1. Google Sheets, which you already have. Use this to pull the contents of the sheet into Redash.
  2. Query Results Data Source (QRDS). Use this to write SQL queries against the data

The problem here is you’re writing a SQL query that Redash sends to Google Sheets, which doesn’t understand SQL.

1 Like

Thank you very much for your reply, but I am still confused. My initial query (#1) is what pulled google sheet into redash. It works and I can see all fields and can do visualizations based on this query #1.

I am now asking about query #2 that is based on query #1 and not google sheets. In this query #2 I would like to only show the front user certain columns and limit them to seeing only last 30 entries, or last month entries, or something like that. and it does not work for some reason.

I am also wondering if query #2 will update automatically when main Google Sheet updates and if the front user will see this updated data.

To limit the records returned just add LIMIT 30 to the end of your second query.

If your QRDS query uses query_xxxx then the google sheets query will execute first whenever you run the QRDS query. If your QRDS query uses cached_query_xxxx then only the cached value will be used, regardless of how old. It sounds from your posts like you want to use query_xxxx to guarantee fresh data.

When you set a date_range parameter for your query with ‘{{date_range.start}}’ and ‘{{date_range.end}}’ simply select the last 30 days (just click the ‘lightening’ icon), apply this filter and save your query. That way everytime user opens this query they’ll see the last 30 days, but they’ll be also able to adjust that parameter as they want.