I'm trying to do a search on a mySQL DB of Job vacancies which match user inputted key words in the job_description column.
The vacancy table has following structure:
CREATE TABLE vacancy (
vacancyID int(5) DEFAULT '0' NOT NULL auto_increment,
companyID int(6) NOT NULL,
job_title varchar(30) NOT NULL,
job_description text,
locationID int(3) NOT NULL,
contract_typeID int(2),
vacancy_salaryID int(3),
date_posted date,
vacancy_status varchar(10),
PRIMARY KEY (vacancyID)
);
locationID matches an ID in a location table;
contract_typeID matches an ID in a contract table;
vacancy_salaryID matches an ID in a salary table;
2 out of 4 trial entries 'job_description' field contain the word 'dog'
NOW if I make this query:
SELECT DISTINCT vacancy.vacancyID, job_title, job_description, location.location, contract.contract_type, salary.salary
FROM vacancy, client, location, contract, salary
WHERE vacancy.locationID = location.locationID
AND vacancy.contract_typeID = contract.contract_typeID
AND vacancy.vacancy_salaryID = salary.salaryID
AND job_description LIKE '%dog%';
It works fine & displays the details
BUT if I want to put in 2 search words i.e......................
SELECT DISTINCT vacancy.vacancyID, job_title, job_description, location.location, contract.contract_type, salary.salary
FROM vacancy, client, location, contract, salary
WHERE vacancy.locationID = location.locationID
AND vacancy.contract_typeID = contract.contract_typeID
AND vacancy.vacancy_salaryID = salary.salaryID
AND job_description LIKE '%negotiation%'
OR job_description LIKE '%dogs%';
Which should pull up 3 results then it goes crazy & pulls out 1633 records which are basically compiled of the first correct record & then the next 2 records (which are the ones I want to display) but with as many permutations of contract_type, Salary & location as possible - hence the additional 1630 records!!
I can stop it by doing a 'Group By' but this just displays the 1st permutation and not the 100% correct record.
Sorry to be a bit lengthy but hope this is understandable & appreciate any assistance.
Dan.