| View previous topic :: View next topic |
| Author |
Message |
nathstevenson Newbie

Joined: 25 Apr 2012 Posts: 4
|
Posted: Wed Apr 25, 2012 6:05 am Post subject: query search criteria - Solved |
|
|
Hi
I am making a database to find filters for sensors based upon the gas to be detected. I have three tables
Gas - Gas Id, Gas Name, Half power bandwidth, centre wavelength
Filter - Filter Id, Filter name, Half power bandwidth minimum, Half power bandwidth maximum, centre wavelength minimum, centre wavelength maximum
Comparison - Comparison Id, Gas id, Filter Id (I don't know if this table is needed)
I want a query that allows the user to put in a gas (or select one in a form) and for the query to take the information in the gas table (Half power bandwidth, centre wavelength) and to find a filter(s) based upon the the Half power bandwidth and centre wavelength fitting within the Half power bandwidth minimum, Half power bandwidth maximum and centre wavelength minimum, centre wavelength maximum stored in the filter table
I know that the criterion will include <= for the minimums and => for the maximums but I am unsure how to make the query compare it to another records field
Thanks in advance to anyone who can help
Last edited by nathstevenson on Thu Apr 26, 2012 1:28 am; edited 1 time in total |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2473 Location: 3rd Rock From The Sun
|
Posted: Wed Apr 25, 2012 6:51 am Post subject: |
|
|
Based ( database pun intended ) on your description above, I suspect something like the following will meet your needs. Of course, you will have to confirm I have entered each table and field name EXACTLY as you entered them in your database table ( that is the CASE ( UPPER / Mixed / lower ) are entered correctly. I took them from what you entered above . . . but . . . you will have to confirm you wrote them correctly, and, I did the same.
| Code: | Select
"Gas"."Gas Name",
"Filter"."Filter Id",
"Filter"."Filter name"
From "Gas",
"Filter",
"Comparison"
Where "Gas"."Gas Name" = :Enter_Gas_Name
and "Comparison"."Gas Id" = "Gas"."Gas Id"
and "Comparison"."Filter Id" = "Filter"."Filter Id"
and "Gas"."Half power bandwidth" BETWEEN "Filter"."Half power bandwidth minimum" and "Filter"."Half power bandwidth maximum"
and "Gas"."centre wavelength" BETWEEN "Filter"."centre wavelength minimum" and "Filter"."centre wavelength maximum" |
Explanation: - The above will return the data in the Select portion, I am not certain exactly which fields you wanted to return, but, I made a guess.
- The user is prompted to input the desired "Gas Name". This is 'defined' from the 'code': Where "Gas"."Gas Name" = :Enter_Gas_Name . The colon ( : )is used to indicate a user prompt. The characters afterwards contains no spaces, so, I used an underscore to simulate words.
- The use of BETWEEN in the Where clause ( two times per your description above ) is used to determine the 'range' of values.
- You can 'test' this Query by following these steps:
- Open your OpenOffice Base file ( *.odb )
- On the left, click on the Queries icon
- Under Tasks, click on: Create Query in SQL View
- Copy and paste the above Query code
- Run the Query ( F5 or Run Query icon on toolbar )
- Save the Query
- Smile and say: "Gee Sliderule, that was easy. Now, all I have to do is mark the forum post as [Solved]".

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 |
|
 |
nathstevenson Newbie

Joined: 25 Apr 2012 Posts: 4
|
Posted: Thu Apr 26, 2012 1:29 am Post subject: thank you very much |
|
|
| Thank you very much your solution worked once I had all of my field titles right. |
|
| 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
|