4

I want to limit the result data in flexible search query.

Let's say query should return only 10 records each time (like LIMIT)

How can I do this?

Joe Sebin
  • 452
  • 4
  • 24
Namu
  • 103
  • 2
  • 6

2 Answers2

6

You already answered your query, you can use LIMIT cause same as we use in MySQL.

Try this

SELECT * FROM {Product} LIMIT 10

or

SELECT TOP 10 * FROM {Product}

For Oracle

SELECT * FROM {Product} WHERE rownum <= 10

Though API

final FlexibleSearchQuery query = new FlexibleSearchQuery("SELECT * FROM {Product}");

query.setCount(10);

Find more detail in helphybris

HybrisHelp
  • 5,518
  • 2
  • 27
  • 65
  • Thank you for your prompt reply! – Namu Jul 02 '18 at 10:35
  • Do you know why it's not working when I try to use impex export tool? ex. `"#% impex.exportItems(""SELECT * FROM {Product} "", Collections.EMPTY_MAP, Collections.singletonList( Item.class ), true, true, -1, -1 );"` I have this error: `Flexiblesearch error: SQL search error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '100 * FROM products item_t0 WHERE (item_t0.TypePkString IN (8796100919378,87961' at line 1 query = 'SELECT TOP 100 * FROM products item_t0 WHERE (item_t0.TypePkString I` – NikNik Mar 08 '19 at 13:53
5

Use the query.setCount(int) method of the API.

Johannes von Zmuda
  • 1,814
  • 8
  • 14