Jump to content
Server Maintenance This Week. ×

This topic is 3857 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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%')
"
 
; "" ; ""
 
)
Link to comment
Share on other sites

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) & "%"
 
)

  • Like 1
Link to comment
Share on other sites

This topic is 3857 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.