Is there a way in wappler to create a query like “Select TOP 10 from XYZ”. Some of my tables have thousands of entries so I don’t want to (or need to) retrieve all of the records. The only way I am able to do this now is by creating a view in sql server but wanted to see if it can be done in wappler without doing this.
I think I know how to make queries in wappler but how do I do a “top 10” selection?
It depends on how you determine the top 10. Do you have a column that registers the top 10? That is the only way to do a select.
You can do this on the serverside using the data formatter.
Do this in server connect steps:
- Create a query from your database table. Uncheck output option.
- Add a repeat step. Select the query as an expression and use the formatter for this expression - under collections category select top and enter the number of records to show. Make sure output option is enabled.
- Add set value step in the repeater. Add a name for it and then bind the value you want to show (product name?)
- On your page, create a repeat region out of this repeat step from the server action and bind the setvalue step inside it.
Actually if you just select to use Paged query and set the limit to 5 it will give you the top 5 records.
Maybe I am missing something but wouldn’t it be easier to just add “top” to the query creator? Like where the distinct setting is.
When I code this query, it looks like this
Select top 10 * from orderlog
Order by orderId desc
This allows me to make a table that just shows me the last 10 orders without having to retrieve thousands of records with a full query.
Right now, I have to create a view in sql to do the top 10 query and then in wappler I do a query on the view.
Creating a paged query and limiting it to 10 records (as in George’s example) does exactly this. It does not retrieve thousands of records, but just 10.
OK, I will try the paged query. Thx.