mercredi 13 février 2019

How to return row with diffrent value if "where" has not been met in MySQL

I have problem with receiving rows if id from one table dont match second one. If zamowienia.id_telefon is null or dont match i dont recive whole row. I want to instead get column crm2018.telefon.numer with "0" or null value. Please help :)

I tried something like that but its obvious syntax eror:

SELECT 
    crm2018.zamowienia.*,
    crm2018.telefon.numer 
FROM
    crm2018.zamowienia 
    JOIN crm2018.telefon 
WHERE
    if (zamowienia.id_telfon != "0")  zamowienia.id_telefon = telefon.id_telefon else crm2018.telefon.numer as "0"

Here's working code but with missing rows.

SELECT 
    crm2018.zamowienia.*,
    crm2018.telefon.numer 
FROM 
    crm2018.zamowienia 
    JOIN crm2018.telefon 
WHERE 
    zamowienia.id_telefon = telefon.id_telefon

Aucun commentaire:

Enregistrer un commentaire