If I have two tables in MySQL… cars and promo
in this query - if in promo have 1/4 of the cars in cars - promoID field for cars only in cars table what will be?
I want get null or empty string for cars Not in promo…
is this correct? i have 1000 entries in cars and 50 entries in promo from cars table but getting promoID 100 results rather only 50…
I rechecked:
[“promoID”]=> string(6) “236511” rather appear one in a case get it in var_dump in 3 times…
What is correct query???
i WANT IF C NOT HAVE ENTRY IN P promoID=“” …OTHERWISE IF IT HAS promoID=C.ID HOW MODIFY QUERY?? NOT SEEM TO WORK BELOW ONLY P CARS APPEAR NOT ALSO IN C WITH promoID=“” THAT IS DESIRED
SELECT
c.*, p.id as promoID
FROM
cars c
LEFT OUTER JOIN promo p
ON c.ID = p.ID
WHERE c.make = 35
GROUP BY MAKE
ORDER BY
c.SYS_CREATION_DATE DESC
LIMIT 0, 100
i don’t understand why you’re using GROUP BY begause you’re not totalling anything
try this –
SELECT c.*
, COALESCE(p.id,'') as promoID
FROM cars c
LEFT OUTER
JOIN promo p
ON p.ID = c.ID
WHERE c.make = 35
ORDER
BY c.SYS_CREATION_DATE DESC LIMIT 100