Reputation: 9802
I am trying to craft code that "Shows the countries that are big by area or big by population but not both". It should show the name, population and area.
The table the code references...
This is my code so far...
SELECT name, population, area FROM world
WHERE area > 3000000 OR population > 250000000 OR name != LIKE '%United States%'
world
contains name
, area
, and population
.
Anyone have any advice?
Upvotes: 3
Views: 609
Reputation: 782785
You can use XOR
for this. It's true if only one of its parameters is true.
SELECT name, population, area
FROM world
WHERE (area > 3000000 XOR population > 250000000)
AND name NOT LIKE '%United States%'
I also changed the way the United States
test is combined. I assume you're trying to exclude United States from the results, so it needs to be AND
.
Upvotes: 3
Reputation: 106147
Use the XOR
(exclusive OR) operator:
SELECT name, population, area FROM world
WHERE area > 3000000 XOR population > 250000000
Upvotes: 2