1

I have the below SQL statement. What I would like to do is include an IF statement to cover the possibility of one of the columns returning a 0 or blank result, there are no 0 ID's. In this case, I'm trying to cover the possibility of the magez_cfv_nations result possibly returning a zero or blank result.

SELECT c.clan_name, n.nation_name, 
    CONCAT(r.rarity_shorthand, " - ", r.rarity_name) AS rarity_text, 
    t.trigger_name, s.skill_name
 FROM `magez_cfv_cards` AS cards
 JOIN `magez_cfv_clans` c ON cards.clan_id = c.clan_id
 JOIN `magez_cfv_nations` n ON cards.nation_id = n.nation_id
 JOIN `magez_cfv_rarity` r ON cards.rarity_id = r.rarity_id
 JOIN `magez_cfv_trigger` t ON cards.trigger_id = t.trigger_id
 JOIN `magez_cfv_skills` s ON cards.skill_id = s.skill_id
2
  • 3
    Are you talking about left joins? Commented Nov 14, 2012 at 15:04
  • I guess that it would sound like. Would I just use LEFT JOIN instead of JOIN up above? Commented Nov 14, 2012 at 15:06

2 Answers 2

2

You need a LEFT JOIN

The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table

Try this

SELECT c.clan_name, n.nation_name, 
    CONCAT(r.rarity_shorthand, " - ", r.rarity_name) AS rarity_text, 
    t.trigger_name, s.skill_name
 FROM `magez_cfv_cards` AS cards
 JOIN `magez_cfv_clans` c ON cards.clan_id = c.clan_id
 LEFT JOIN `magez_cfv_nations` n ON cards.nation_id = n.nation_id
 JOIN `magez_cfv_rarity` r ON cards.rarity_id = r.rarity_id
 JOIN `magez_cfv_trigger` t ON cards.trigger_id = t.trigger_id
 JOIN `magez_cfv_skills` s ON cards.skill_id = s.skill_id
Sign up to request clarification or add additional context in comments.

Comments

1

the function you should use is IIF() and its syntax is

IIF([condition],[if true],[if false])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.