How to set default value in SubQuery result using mysql
How to set default VALUE in SubQuery result using mysql
SELECT
p.`id`, p.`name`, p.`class_name`, cpd.`status_team`,
cpd.`home`, cpd.`guest`, cpd.`mvp`, cpd.`oscar`,
cpd.`wam`, cpd.`status`, cpd.`added_date`,
(SELECT result FROM result_cards WHERE `id` = cpd.`result`) AS DEFAULT(`result`)
FROM `cron_players_data` cpd
INNER JOIN `players` p ON cpd.`player_id` = p.id
WHERE cpd.`added_date` = '2012-03-29' AND cpd.team_id = '15'
when I remove this DEFAULT () the query will run normally. Actually, I want the default result to be 0 or help is definitely appreciated
+3
source to share
2 answers
You have to postpone the sub-connection request. But I can't figure out what you are trying to do with DEFAULT (). You will need to explain what you are trying to achieve.
SELECT
p.`id`, p.`name`, p.`class_name`, cpd.`status_team`,
cpd.`home`, cpd.`guest`, cpd.`mvp`, cpd.`oscar`,
cpd.`wam`, cpd.`status`, cpd.`added_date`,
IFNULL(rc.`result`, 0) AS `result`
FROM `cron_players_data` cpd
INNER JOIN `players` p
ON cpd.`player_id` = p.id
LEFT JOIN result_cards rc
ON cpd.`result` = rc.id
WHERE cpd.`added_date` = '2012-03-29'
AND cpd.team_id = '15'
+1
source to share
IFNULL solution
SELECT
p.`id`,p.`name`,p.`class_name`,cpd.`status_team`,cpd.`home`,cpd.`guest`,cpd.`mvp`,
cpd.`oscar`,cpd.`wam`,cpd.`status`,cpd.`added_date` ,
IFNULL((SELECT result FROM result_cards WHERE `id` = cpd.`result`),0) AS `result`
FROM `cron_players_data` cpd INNER JOIN `players` p ON cpd.`player_id` = p.id
WHERE cpd.`added_date` = '2012-03-29' AND cpd.team_id = '15'
+4
source to share