DeathRobot Posted October 7, 2013 Posted October 7, 2013 Hi. I'm using a global search field ("searchString") and SQL to populate a portal. For example, when searching a People table, I have: SELECT id FROM People WHERE name LIKE %searchString% OR category LIKE %searchString% This works great. However, I would like to extend the search so that a user could search on a company name and all related people from that company would be returned: SELECT id FROM People WHERE name LIKE %searchString% OR category LIKE %searchString% OR [companyName from the related Company table] LIKE %searchString% I've tried every iteration of JOIN, LEFT JOIN, UNION, etc. that I can think of, but cannot get the syntax correct. Any help is very much appreciated! Michael
Kris M Posted October 8, 2013 Posted October 8, 2013 try ExecuteSQL ( "SELECT id FROM People WHERE name="searchstring1" OR category='searchstring2' ; "" ; "" ) Hi. I'm using a global search field ("searchString") and SQL to populate a portal. For example, when searching a People table, I have: SELECT id FROM People WHERE name LIKE %searchString% OR category LIKE %searchString% This works great. However, I would like to extend the search so that a user could search on a company name and all related people from that company would be returned: SELECT id FROM People WHERE name LIKE %searchString% OR category LIKE %searchString% OR [companyName from the related Company table] LIKE %searchString% I've tried every iteration of JOIN, LEFT JOIN, UNION, etc. that I can think of, but cannot get the syntax correct. Any help is very much appreciated! Michael
DeathRobot Posted October 9, 2013 Author Posted October 9, 2013 Hi Kris, Thanks for your reply. I may have been unclear in my question. The trouble I'm having is matching records against a related table using just one search string, like so: ExecuteSQL ( "SELECT id FROM People WHERE name="searchstring" OR COMPANYTABLE.companyName='searchstring' ; "" ; "" ) The syntax is not correct (that's the issue I'm having!) but I want to pull all id's from the People table where the search string either matches a name in the People Table OR the search string matches a company name in the Company Table. So if I searched on "Bob Smith', Bob's record would be returned. If I searched on Xerox, all the people who were related to Xerox would be returned. Michael
mr_vodka Posted October 10, 2013 Posted October 10, 2013 INNER JOIN will give you all the related records that match your parent records. Then you should be able to put both conditions in the WHERE clause but keep in mind that it will only display records in which there is a parent with related child records.
DeathRobot Posted October 10, 2013 Author Posted October 10, 2013 Thanks, John. I'm interpreting your answer to be something like this? If so, there still seems to be something wrong with my syntax. I get a '?' result with it: ExecuteSQL ( " SELECT id FROM People INNER JOIN Companies ON People.id_Company=Companies.id WHERE LOWER(Companies.name) LIKE LOWER('%searchString%') " ; "" ; "" )
mr_vodka Posted October 10, 2013 Posted October 10, 2013 Try putting it in the parameter. For example try something like: ExecuteSQL ( " SELECT company.ID, company.name, people.ID, people.name FROM people LEFT JOIN company ON people.companyID = company.ID WHERE LOWER(company.name) LIKE ? " ; "" ; ""; "%" & Lower(company::gSearch) & "%" ) 1
David Jondreau Posted October 10, 2013 Posted October 10, 2013 Is LOWER() an SQL function? I'm suspect you can't use it this way. DJ
DeathRobot Posted October 11, 2013 Author Posted October 11, 2013 Ah, thanks so much, John. That works perfectly. And David, the LOWER function appears to work just fine. Michael
Recommended Posts
This topic is 4117 days old. Please don't post here. Open a new topic instead.
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 accountSign in
Already have an account? Sign in here.
Sign In Now