0

5th q in challenge says that we need tge ages of lions and bears. but according to the given answer they are using IN clause which means lions or crocodiles and bears or birds. so how come this? Is it a mistake?

1st Aug 2016, 9:55 AM
Anand Nain
Anand Nain - avatar
4 Réponses
+ 1
It depends on how you read it, the first sentence states that you Need the ages of bears and lions, however they also clarify that the result of query one will return ages of bears and birds, same with query two except its crocodiles and lions. However seeing how theres no good way of knowing which rows are what animal in the result a more correct query would be: SELECT age FROM zoo1 WHERE animal = 'bear' UNION SELECT age FROM zoo2 WHERE animal ='lion' Or if you keep the queries in the question as is and also select the animal column, then you'd get a result table where you could filter on the animals you want.
1st Aug 2016, 11:15 AM
Johan Sandahl
Johan Sandahl - avatar
+ 1
Union combines the result sets from the queries and remove any duplicates. Union all combines the result sets but keeps all the rows.
1st Aug 2016, 3:08 PM
Johan Sandahl
Johan Sandahl - avatar
0
what is difference union and union all??
1st Aug 2016, 3:04 PM
meri
meri - avatar
0
yeap understand .thanks
1st Aug 2016, 3:11 PM
meri
meri - avatar