Page 1 of 1

[Solved] Need Help Making a Query

Posted: Tue Jun 26, 2018 8:45 pm
by needhelplz
I have a table recording documents used for general inventory and finding the documents (linked below). My boss thinks this is not good enough and wants 3 different tables. He wants to be able to search a keyword into a query and find what he is looking for. Like "Meadows" and all the files with the word "Meadows" shows up along with the file type and location. It would mean a lot if you would help. Thank you.

Re: Need Help Making a Query

Posted: Wed Jun 27, 2018 1:46 am
by mgroenescheij
Has your boss also told you why he want's three tables?
Meadow is not a keyword it's just a word in your table.
What you have made is much easier to put in a spreadsheet where you can use the standard filter to search for words.

Re: Need Help Making a Query

Posted: Wed Jun 27, 2018 11:14 am
by keme
"Quick and dirty", searching in filename and filetype, excluding record key and physical file location from the search:

Code: Select all

SELECT * FROM "Files" where ("File Name" || "File Type") like ('%' || :search_term || '%');
A cleaner approach would be to test the fields individually, but the above is faster on some platforms. It will also match records where the search term "crosses the border", as it were. (Where file name ends with "...Mead" and File type starts with "ows...", using your example search term.)

Note that if your database is on a different SQL platform (moving from "embedded data" to a separate server), the SQL syntax may be slightly different (use of single vs. double quotes, input variable prompt).

Re: Need Help Making a Query

Posted: Wed Jun 27, 2018 3:43 pm
by UnklDonald418
As Keme demonstrated searching is one of the strengths of databases. There are also search functions available in SQL, for instance

Code: Select all

SELECT * FROM "Files" WHERE LOCATE( :Enter_Search_String, "File Name" || "File Type" ) > 0
would also work.