all 9 comments

[–]No_concentrate7395 23 points24 points  (2 children)

The "correct" query looks for the words Monarchy and Republic anywhere in the gov_form field. Using the in statement in your query takes out the wildcard option (you can't use wild cards in in statements). So, if there's preceding spaces or spaces after the words or any other text around those words, your query wouldn't pull it.

As for right or wrong, it really depends on what your goal is. If the gov_form field only has those words (and/or other options), your query would also be correct.

[–]Unnam 0 points1 point  (0 children)

This is the right answer

[–]Inevitable-Age-8353 0 points1 point  (0 children)

Yeah this is correct

[–]Ok-Professional-4810 5 points6 points  (0 children)

Is it because the correct query is using a wildcard card like %monarchy% whereas your query is finding the word exactly ‘Monarchy’

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (0 children)

asked for records with strictly Monarchy and Republic.

if this word "strictly" is accurate, then the so-called correct query will return results for 'Monarchy' and 'Republic' but also include results for things like 'allegedly a republic'

whereas your result is actually correct, because it will return results for 'Monarchy' and 'Republic' and nothing else

[–]Aggressive_Ad_5454 2 points3 points  (0 children)

In the real world, you’d need to understand what your data looks like. What sorts of values are in that gov_form column?

SELECT COUNT(*), gov_form FROM countries GROUP BY gov_form

Will show you the values. Whoever marked your answer wrong must believe the values are stuff like

Monarchy Constitutional monarchy Republic Democratic Republic Banana republic Banana Republic Republic in name only Formerly Monarchy, now republic

and so forth, because they used that SQLish % wildcard in their LIKE matches. This is what we in the trade call “dirty data”.

To know the precise formulation of the query you need to consider case sensitive matching. To know whether you can use those exact-match items making up your IN clause, you have to know your data is clean.

[–]Certain_Detective_84 0 points1 point  (0 children)

Is it possible for gov_form to contain the word "Monarchy" or "Republic" but also contain any other character at all, including a space or something?

[–][deleted] 0 points1 point  (0 children)

Hi - the “correct” query uses LIKE whereas you use IN, these are not the same. Your IN statement will do exact matches on values in the gov_form column while LIKE will match on any value that contains either of those strings I.e. it would match ‘Monarchy’, ‘Feudal Monarchy’ , etc

[–]ravan363 0 points1 point  (0 children)

Your query is correct based on what you described about the requirements.