DB관련/MySQL
SQL의 IFNULL()함수 MySQL의 COALESCE()함수로 사용
saltdoll
2019. 3. 2. 09:30
반응형
MS SQL에서 IFNULL(컬럼, 0) 컬럼값이 null이면, 0을 넣는 함수가 있습니다.
MySQL에서는 COALESCE(컬럼, 0)을 이용해서 null이면, 0을 넣는 함수를 사용합니다.
출처: ISNULL(value, 0) in WHERE clause MYSQL
I believe you are trying to use the IFNULL()
function. IF you replaced with IFNULL
that should fix your query.
I suggest you go one step further and use COALESCE()
instead of IFNULL()
, since COALESCE()
is part of the SQL standard (and IFNULL()
is not).
SELECT sc.no, scl.quantite, scl.description, scl.poids,
scl.prix, sl_ref.refsl, sl_ref.codetva, sl_ref.tauxtva, sl_ref.compte
FROM shop_commande
AS sc, shop_commande_ligne AS scl, selectline_ref AS sl_ref
WHERE sc.id = scl.shop_commande_id
AND sl_ref.refshop = COALESCE(scl.shop_article_id, 0)
AND sc.id NOT IN (SELECT id_command FROM selectline_flag)
반응형