Hello,
I have the following sql table + data:
CREATE TABLE IF NOT EXISTS `job_requires` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Job_id` bigint(20) unsigned NOT NULL,
`Group_Index` int(11) NOT NULL,
`Field_id` bigint(20) unsigned NOT NULL,
`Field_Value` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO `job_requires`
(`id`, `Job_id`, `Group_Index`, `Field_id`, `Field_Value`)
VALUES
(1, 7, 1, 11, 50),
(2, 7, 1, 14, 50),
(3, 7, 1, 11, 59),
(4, 7, 2, 14, 1),
(5, 7, 2, 11, 2),
(6, 8, 1, 14, 55),
(7, 8, 1, 11, 50),
(8, 8, 1, 14, 59),
(9, 8, 2, 11, 60),
(10, 8, 2, 14, 61);
I need to get all ‘Job_id’ by filtering that based on the ‘Field_id’+’Field_Value’ fields.
I want the query to be somthing like:
SELECT job_requires.Job_id
FROM job_requires
WHERE (Field_id=11 AND Field_Value=50) AND (Field_id=14 AND Field_Value=1)
My problem is that I want query to be based also on the Group_Index field:
Only if ‘Job_id’ in my previous query have both conditions, and those conditions have the same Group_Index It should be in the query’s result.
UPDATE: I don’t know how many filters the query will have, it could be also:
SELECT job_requires.Job_id
FROM job_requires
WHERE (Field_id=11 AND Field_Value=50) AND (Field_id=14 AND Field_Value=1) AND (Field_id=16 AND Field_Value=56) AND (Field_id=12 AND Field_Value=26)
I hope you understand my problem, because my english is not great 🙁
Thank you very much
1 Answer