Hello Everyone,
I need to build a query and I'm having a terrible time getting my head around it. Here are the details of the tables:
Table1: MESSAGES
Table2: FOLDERS
Each message, in the messages table is assigned a folder by FOLDER_ID.
I want to count messages in the MESSAGES table that match a FOLDER_NAME, and not the FOLDER_ID. The folder name is stored in the FOLDERS table.
The folder names change over time, so I use "LIKE" to find keywords in the folder name.
SO - how do I structure the query to say:
SELECT count(*) from MESSAGES where completed = 0 AND FOLDERID = ??????? (name?)
You see, I want to query by folder name which is in a separate table. Any ideas?
I tried this but get an error...
I need to build a query and I'm having a terrible time getting my head around it. Here are the details of the tables:
Table1: MESSAGES
Table2: FOLDERS
Each message, in the messages table is assigned a folder by FOLDER_ID.
I want to count messages in the MESSAGES table that match a FOLDER_NAME, and not the FOLDER_ID. The folder name is stored in the FOLDERS table.
The folder names change over time, so I use "LIKE" to find keywords in the folder name.
SO - how do I structure the query to say:
SELECT count(*) from MESSAGES where completed = 0 AND FOLDERID = ??????? (name?)
You see, I want to query by folder name which is in a separate table. Any ideas?
I tried this but get an error...
Code:
sql = "select count(*) from kc_message inner join kc_folders on kc_Messages.folderid = kc_folders.folderid where kc_messages.completedate is null and (kc_messages.createdate >= to_date('" & hours_ago & "','mm/dd/yyyy hh:mi:ss " & am_or_pm(1) & "')) and kc_folder.lable like '" & searchstr & "%'"