How to limit the result data in flexible seach query - database

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?

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

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

Related

Codename One Database print range of rows

I am using Codename One to get data from a database and display it in a table.
This is functioning quite well, and now I am trying to add a feature that limits the number of items that are shown in the table. To get there, I want to retrieve a selected number of columns from the database .
Unfortunately, common java sql operations do not seem to work. Below is what I have so far. All approaches don't throw any errors, but also also don't display the desired range or ranges. Another way to obtain a selection would probably be an ArrayList, but I would very much like to stick with a direct approach, since this appears to be relatively easy and elegant solution.
db = display.getInstance().openOrCreate("MyDB.db");
db.execute("CREATE TABLE IF NOT EXISTS Termine (Date NOT NULL,Event NOT NULL, Date_String NOT NULL)");
// prints the entire number of items from the database
cur = db.executeQuery("select * from (select * from Termine order by Date) where Date >= 5;");
// doesn't print anything
cur = db.executeQuery("SELECT * from ( select m.*, Date r from Termine m ) where r > 4 and r < 10;");
// doesn't print anything
cur = db.executeQuery("SELECT * from ( select m.*, Date r from Termine m ) where r BETWEEN 5 AND 10;");
while (cur.next()) {
Row currentRow = cur.getRow();
String event = currentRow.getString(1);
System.out.println(event);
}
Is my approach feasible? Any help would be greatly appreciated.
You can use the LIMIT SQL keyword as explained here.
SELECT column_list FROM table LIMIT row_count OFFSET offset;
A good practice is to search for "sqlite" and the SQL feature you are looking for as mobile SQL databases on all platforms are based on sqlite which has some quirks.

SQL Query... I'm new so this is probably easy

I can write simple SELECT statements for my SSRS reports but I have run into a wall trying to figure out how to do this query and I'm stumped. I have a table, and it has an entry in it showing me that a particular process is done. The process is Operation_Seq_NO 60 and the QTY_GOOD is 1. There IS NO ENTRY for operation_seq_no with an 80 so it goes on the report. As soon as an 80 entry hits the table, it needs to go off the report. Sounds simple but totally got me stumped. I attached a pic or it in tabular format to maybe help someone understand the issue.
You can use not exists() or not in() to filter rows that have a corresponding row with operation_sec_no = 80 like so:
using not exists():
select *
from labor_ticket as t
where not exists (
select 1
from labor_ticket as as i
where t.transaction_id = i.transaction_id
and i.operation_sec_no = 80
)
or with not in():
select *
from labor_ticket as t
where transaction_id not in (
select transaction_id
from labor_ticket as i
where i.operation_sec_no = 80
)

limiting results in sybase ASE between a particular range

I have a search screen which allows the user to search information and it populates a grid. Some of the search results are returning a huge amount of data. I am trying to create a paging grid so that I only bring from the store procedure 10 or 20 results at a time. (I already have a paging grid in the UI)
I am trying to do something like this:
select * from wl_eval limit 1, 20
The query above will return only the first 20 records. How would I be able to accomplish that in Sybase ASE? Unfortunately, for my client project we are using Sybase. I know that in other database engines we could have used the query I mention above. I also know we can use SET ROW COUNT 20 but this wont work if I want a particular range, say from 30 to 50.
Any thoughts?
Add TOP numberofrecords you want to return
DECLARE #intStartRow int;
DECLARE #intEndRow int;
SET #intStartRow = (#intPage -1) * #intPageSize + 1;
SET #intEndRow = #intPage * #intPageSize;
WITH wl_eval AS
(SELECT field,
ROW_NUMBER() OVER(ORDER BY intID DESC) as intRow,
COUNT(intID) OVER() AS intTotalHits
FROM tblBlog)
SELECT field, intTotalHits FROM wl
WHERE intRow BETWEEN #intStartRow AND #intEndRow
SELECT TOP 20 <column list>
FROM YourTable
ORDER BY <list>

How to return a single record from a database table based on id in lua?

local function getListRecord(id)
local select_stmt = db:prepare("SELECT * FROM list where id = ?")
select_stmt:bind_values(id)
select_stmt:step()
local r = select_stmt:get_uvalues()
select_stmt:finalize()
return r
end
for the above code i am getting duplicate record created. how can i return single record
Please help me, thanks in advance
Thank you,
Madan mohan.
Use of DISTINCT is one way. Another may be to use LIMIT 1. The syntax and options may vary depending on which database you run the query against.
Examples:
SELECT DISTINCT * FROM list where id = ?
SELECT * FROM list where id = ? LIMIT 1

Get Last page no in a pager link like stackoverflow

How to get last page no like stackoverflow.com pagination in Sql server 2005
Try somethign like this
DECLARE #NumberPerPage INT
SELECT #NumberPerPage = 50
SELECT CEILING(COUNT(*) / CAST(#NumberPerPage AS FLOAT)) NumberOfPages
FROM TABLE
Assuming a page size of 10:
select case when count(*) % 10 = 0 then count(*)/10 else count(*)/10 + 1 end as lastPageNumber from posts;
As you can see, it's a little tedious to do this kind of stuff purely in SQL. What high level language are you using? You can implement the logic in your programming language and then just do this SQL query to get the count of the number of items:
select count(*) from posts;

Resources