Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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

 

  • Author

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

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.

  • Author
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%')
"
 
; "" ; ""
 
)

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

Is LOWER() an SQL function? I'm suspect you can't use it this way.

 

DJ

  • Author

Ah, thanks so much, John. That works perfectly. And David, the LOWER function appears to work just fine.

 

Michael

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.