Answer the question
In order to leave comments, you need to log in
How to make a selection on 2 identical fields?
Table example: sqlfiddle
I'm trying to figure out how to make a selection on 2 fields, for example, car_brand and name. The point is that Ivan can have several cars, I'm trying to select cars of a certain person and only one brand, after the selection I write the ID to the database and set status = 1 and continue the selection. That is, in this example, after the first request, I should get: the 1st and 5th lines. (Ivan Ivan and Honda Honda)...
I tried different ways, it doesn't work.
UPD:
Modeling what I'm trying to do.
1. sqlfiddle.com/#!9/0ecfec/80
2. sqlfiddle.com/#!9/dede9/3
3. sqlfiddle.com/#!9/375b08/13
4. sqlfiddle.com/#!9/968202 /1
5.sqlfiddle.com/#!9/24944/1
But I'm not sure if this will always work correctly.
Answer the question
In order to leave comments, you need to log in
UPD2: In short: From long dialogues - the task is to bypass the entire database, select 1 user each, then select all the same user-brand pairs, do shamanism with them, write back status 1.
1) Get possible user-machine pairs, remember in an array .
SELECT distinct
`name`, `car_brand`
FROM
`drivers`
where `status` = 0
SELECT *
FROM `drivers`
where `name` = '$name' and `car_brand`= '$brand' and `status` = 0
SELECT *, COUNT(car_brand) as total_cars
FROM
`drivers`
GROUP BY car_brand, name
SELECT *
FROM `drivers`
where
`car_brand` = "Honda"
and
`name` = "Иван"
and
`status` = 0
LIMIT 2
id car_brand name status
------------------------------------------
1 Honda Иван 0
5 Honda Иван 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question