[Solved] Query/report for a subset, not entire table

Discuss the database features
Post Reply
hectorheadgear
Posts: 3
Joined: Sun Feb 27, 2022 10:18 am

[Solved] Query/report for a subset, not entire table

Post by hectorheadgear »

Hello everybody! I'm sure this is a silly question, but I'm new to this kind of software.
I have created a table of songs which includes the name of the song, its key, its tempo and capo position. I want to be able to create a report/query where I simply return a list of songs in the key of "B" or a tempo of 120, etc. I have tried to use the query wizard, and instead of the desired result, it's just sorting the whole table by key alphabetically. So instead of getting just 5 songs in the key of B, I'm getting all the songs sorted by key alphabetically.
I hope you can help; it would be a real help for me to have this functionality. Thank you in advance!
 Edit: Changed subject, was Song List 
Make your post understandable by others 
-- MrProgrammer, forum moderator 
Last edited by MrProgrammer on Tue Mar 08, 2022 4:46 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 4.1.10 on Windows 10
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Song List

Post by UnklDonald418 »

It would be best if you could upload a sample of your database.
[Forum] How to attach a document here
Then we can help you design queries to achieve the results you need.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Song List

Post by Villeroy »

Create a query in SQL mode and try any of these:

Code: Select all

SELECT * FROM "Table" WHERE "KEY" = :Enter_Key
SELECT * FROM "Table" WHERE "TEMPO" = :Enter_Tempo
SELECT * FROM "Table" WHERE "TEMPO" = :Enter_Tempo  AND "KEY" = :Enter_Key
SELECT * FROM "Table" WHERE ("TEMPO" = :Enter_Tempo OR :Enter_Tempo IS NULL)  AND ("KEY" = :Enter_Key OR :Enter_Key IS NULL)
Replace the double-quoted names with the actual ones.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
hectorheadgear
Posts: 3
Joined: Sun Feb 27, 2022 10:18 am

Re: Query/report for a subset, not entire table

Post by hectorheadgear »

Here is my database. Thank you for any help you can provide me with!
Attachments
solo act database.odb
(13.79 KiB) Downloaded 95 times
OpenOffice 4.1.10 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Query/report for a subset, not entire table

Post by Villeroy »

TABLES
The column types should be as small as possible and as large as necessary. This makes your table efficient with many thousands of rows.
The Tempo has to be an integer number otherwise the figures would be sorted alphabetically (90 is greater then 100). I removed the text "/" in one row and applied column type "Small Integer".
I turned all remaining text columns into VARCHAR_IGNORECASE so they compare case-insensitively. If you have a reason why you want "A" treated differently from "a", this can be fixed so the form would work anyway. It was just easier for me to do it this way.
I reduced Key and Postion to max.3 characters.

I added a filter table with one row and various text and integer columns.

QUERIES
I added a query which explicitly selects the filter row where ID=0, so you may add more rows with filter criteria and this one is still identifyable.
I added a parameter query which selects all columns from the Materials table. When you open this query you will be prompted for various parameters.

FORM
The form has the filter table query as a main form and the parameter query as subform. The parameters are substituted by the corresponding columns of the parent form. I defined a default sort order (Key, ascending) to the subform. This order is applied every time when you load the form. It can be overriden for the current session.

You enter criteria into the green boxes, click [OK] and the grid shows the resulting rows. Missing criteria are ignored. The cancel button resets the criteria form to its previous state.

Further reference: [Example #1] Filter/Search with Forms (leveraging SubForms)
Attachments
solo act database2.odb
Another power filter form
(16.89 KiB) Downloaded 110 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
hectorheadgear
Posts: 3
Joined: Sun Feb 27, 2022 10:18 am

Re: Query/report for a subset, not entire table

Post by hectorheadgear »

Thank you for your help. This problem is solved!
OpenOffice 4.1.10 on Windows 10
Post Reply