| View previous topic :: View next topic |
| Author |
Message |
cilt Power User

Joined: 20 May 2010 Posts: 89
|
Posted: Sun Sep 12, 2010 7:06 pm Post subject: query so show ony first or last record -SOLVED |
|
|
can I make a query that will display only the last record in a table
using the GUI ?
or some other way ?
Last edited by cilt on Sun Sep 12, 2010 8:39 pm; edited 1 time in total |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2474 Location: 3rd Rock From The Sun
|
Posted: Sun Sep 12, 2010 8:03 pm Post subject: |
|
|
cilt:
You said / asked:
| cilt wrote: | can I make a query that will display only the last record in a table
using the GUI ?
or some other way ? |
The answer is, probably yes, BUT, I use the word probably, because I am not 100% certain I understand the purpose and what you want.
Let me attempt to explain a few thing . . . if this does not help, maybe if you can be clearer of what you want.
- A thing about a database Query . . . it is composed by a a SELECT statement ( the statement starts with the word SELECT ).
- You CAN ( have the ability ) SORT ( Query key word of ORDER ) by any field, or, combination of fields.
- The order a Query will come back . . . is 'arbitrary' . . . UNLESS you define a specific order.
- You can create a Query with the GUI ( Graphic User Interface ), and, define SORT ( ORDER by clause ) for the 'sequence' of the rows returned.
- Therefore, you could have TWO Queries, one that SORTS in ASCENDING order, and, a SECOND that SORTS in DESCENDING order. That way, the FIRST record of one Query, will be same as the LAST record of the second Query.
- The OpenOffice BASE parser, does NOT allow the ability to 'control' the number of records returned ( that is the 'bad' news ) . . . BUT . . . the database driver . . . probably HSQL . . . DOES have an option to 'restrict' the number of records to be returned. For example, it could be 1, or 25, or 100 . . . whatever.
- The SYNTAX to return only ONE record , verses, 25, or, 100 is:
| Code: | LIMIT 1
LIMIT 25
LIMIT 100 |
Therefore, if you first create your Query using the GUI ( Graphic User Interface ) . . . and next, choose EITHER:
- On the TOOLBAR . . . press the icon . . . Switch Design View On/Off ( yellow triangle at the southwest corner )
- Menu: View -> Switch Design View On/Off
all you have to do is . . . at the end add the LIMIT 1 as I identified above.
Next, to STOP the OpenOffice Base Parser from saying an error, either:
- On the Toolbar, press the icon: Run SQL command directly ( SQL with a green check mark )
- From the Menu: Edit -> Run SQL command directly
Run the Query ( F5, toolbar icon Run Query )
Save the Query
Say, "Gee Sliderule, that was easy. Thanks. Now, all I have to do is mark this forum post as . . . [Solved] on my first post Title.
Summary: Yes, you can return 1 or any specific number of records . . . and . . . by having TWO Queries, with OPPOSITE sort ( ORDER ) definitions . . . AND by passing the SQL directly to the database engine . . . I think your needs are met.
I hope this helps, please be sure to let me / us know.
Sliderule
Thanks to add [Solved] in your first post Title ( edit button ) if your issue has been fixed / resolved. |
|
| Back to top |
|
 |
cilt Power User

Joined: 20 May 2010 Posts: 89
|
Posted: Sun Sep 12, 2010 8:40 pm Post subject: |
|
|
Thanks for that it works with views as well  |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2474 Location: 3rd Rock From The Sun
|
Posted: Sun Sep 12, 2010 8:49 pm Post subject: |
|
|
Glad things are working for you.
Just for others reading this . . . about the OpenOffice Base Parser . . . since the Parser will NOT be used . . . that means you also do NOT have the ability to define the Query as a Parameter Query.
That means, you will NOT be able to 'prompt' a user for input . . . AND . . . include a LIMIT clause. Also, since the Parser will not be used, any DATES will have to be defined in YYYY-MM-DD format . . . but . . . if you first use the GUI ( Graphic User Interface ) to include a date in 'local' format . . . it translates the date to database format.
Sliderule |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|