Sign in to follow this  
Followers 0
Djordhan

SQLite multi condition SELECT

6 posts in this topic

HI there,

Here's the problem: A record can be Pending or Done.

I want to retrieve the oldest Pending item. But the following statement probably looks through the entire database (FROM Request) therefore select the oldest Done.

How can I select the oldest Pending ?

Is it even possible with SQLite or the function is only available in MySQL ?

WHERE Status='Pending' AND Date=(SELECT MIN(Date) FROM Request)

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I use AutoIt to access ADS (Advantage Database Server), but for a similar query, I don't bother with a compound select statement. Just something like: "SELECT MIN[DATE]) FROM TABLE WHERE [sTATUS] = 'Pending';"

Edit: Pardon, I may have spoken too soon, if you're after the entire record, then you're probably going the correct route with an embedded select. Such syntax does work fine for me, but that is accessing ADS and not SQLite. Perhaps SQLite only uses a subset of full SQL, and the MIN and MAX date functions are not available? That would be easily researched. Have you installed a COM error handling routine to retrieve the actual error data?

Edited by Spiff59

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

SQLite is ... well "Lite" but certainly not a toy. Standard SQL can do this easily, the only problem being that there's no such beast as "standard SQL" in practice. One good way to do that on any decent SQL RDBMS is:

select * from table where status = 'Pending' order by date asc limit 1;

If you have an index on date, then it should run very fast. Usefulness of such index mainly depends on selectivity of date and size of table (and average size of rows).

BTW SQLite does of course support Min, Max and any imbrication of subselects, up to insanity.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

select * from table where status = 'Pending' order by date asc limit 1;

Works like a charm. Thank you!

Share this post


Link to post
Share on other sites

BTW SQLite does of course support Min, Max and any imbrication of subselects, up to insanity.

"Imbrication"...had to google that one.

jchd = always educational. It's like reading George Will, but about RDBMS instead of baseball.

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Sorry for that frenchism, if ever it's one. I could have used "complex arrangement" instead.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0