I am new to SQL programming.
I have a table job where the fields are id
, position
, category
, location
, salary range
, description
, refno
.
I want to implement a keyword search from the front end. The keyword can reside in any of the fields of the above table.
This is the query I have tried but it consist of so many duplicate rows:
SELECT a.*, b.catname FROM job a, category b WHERE a.catid = b.catid AND a.jobsalrange = '15001-20000' AND a.jobloc = 'Berkshire' AND a.jobpos LIKE '%sales%' OR a.jobloc LIKE '%sales%' OR a.jobsal LIKE '%sales%' OR a.jobref LIKE '%sales%' OR a.jobemail LIKE '%sales%' OR a.jobsalrange LIKE '%sales%' OR b.catname LIKE '%sales%'
In the search grid, choose tables and views of interest or leave them all checked. To narrow down the MySQL search data scope, select the table, views, numeric, text type, and date columns checkboxes. To start the search, click the Find button or hit the Enter key from the keyboard.
There is a Schemas tab on the side menu bar, click on the Schemas tab, then double click on a database to select the database you want to search. Then go to menu Database - Search Data, and enter the text you are searching for, click on Start Search.
Keywords are words that have significance in SQL. Certain keywords, such as SELECT , DELETE , or BIGINT , are reserved and require special treatment for use as identifiers such as table and column names. This may also be true for the names of built-in functions.
For a single keyword on VARCHAR fields you can use LIKE
:
SELECT id, category, location FROM table WHERE ( category LIKE '%keyword%' OR location LIKE '%keyword%' )
For a description you're usually better adding a full text index and doing a Full-Text Search (MyISAM only):
SELECT id, description FROM table WHERE MATCH (description) AGAINST('keyword1 keyword2')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With