Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use a keyword in a query??

Status
Not open for further replies.

EdLentz

Technical User
Mar 20, 2002
85
0
0
US
I have a table with no index and there are only keywords. Here is the layout:
Screenshot_2023-05-25_110504_juxvuj.png


So there is a keyword I want the value from I have tried

Code:
select * from freepbx_settings like %FREEPBX_SYSTEM_IDENT%

FREEPBX_SYSTEM_IDENT is the keyword

freepbx_settings is the table

I know this should be easy but I am having a brain fart with this. Any help much appreciated!
 
It's not sufficient to know the data structure to know what you need, but my first guess would be

Code:
select * from `freepbx_settings` WHERE `keyword`='FREEPBX_SYSTEM_IDENT'

Besides that your code will just error, I don't get why you even consider using LIKE. LIKE is for pattern matching, that would be useful if there are many keywords that have the same keyword pattern, i.e. having the same prefix or suffix.

Chriss
 
Thanks Chriss
I only tried Like because it was suggested in some searches I did

Code:
select * from `freepbx_settings` WHERE `keyword`='FREEPBX_SYSTEM_IDENT'

gives me the whole row of info. I just need the value in that row

Thanks
 
I figured it out

Code:
select `value` from `freepbx_settings` WHERE `keyword`='FREEPBX_SYSTEM_IDENT'

Got me what I wanted.

Thanks for the help Chriss!
 
You can still get a broader search, as you may have initially intended, with the LIKE operator.

SQL:
select * from `freepbx_settings` WHERE `keyword` LIKE '%FREEPBX_SYSTEM_IDENT%';

 
Of course but a more useful usage of like is when you don't know the full keyword, then you can query this, for example:

Code:
select * from `freepbx_settings` WHERE `keyword` LIKE '%PBX%';

My guess is that you will get the same record with Spamjim's query and perhaps a few more records with my query. It's still always more straightforward and better to not make LIKE your standard tool to use for any query.

Chriss
 
Now all I need to do is get this into a variable that I can use. I wish to use it in an email that I have setup. Seems like it should be easy. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top