-1

There is no error, but the results show the values excluding the row that meets both conditions. The result shows 3, in fact, it should be 4 excluding data that has 22 for age and UK for the country. Any idea why the result is 3, not 4?

SELECT COUNT(*) FROM CUSTOMERS WHERE CUSTOMERS.AGE = '22' OR CUSTOMERS.COUNTRY = 'UK';

enter image description here

OLIVE99
  • 1
  • 2
  • Please share more details, like the table structure, sample input data, and the database system you are using – Nico Haase Oct 09 '22 at 10:47
  • Also, **why** should the result be 4? Can you explain which four rows of these five should match the given criteria? – Nico Haase Oct 09 '22 at 10:48
  • I'm just using sample data that's available online to understand how to use where clause correctly. Any idea why customer id 3 was excluded when I run my code? – OLIVE99 Oct 09 '22 at 10:50
  • I'm trying to fetch the number of rows that has either age 22 or country UK and I thought my code should be able to fetch 4 as there are four rows meet the conditions. – OLIVE99 Oct 09 '22 at 10:51
  • 1
    Customers 2, 3 and 4 meet your criteria. That's three customers. Why do you think there are four? Please list the four customer ids you think should be counted. – MatBailie Oct 09 '22 at 10:56
  • 1
    Try this, and tell me how many rows you see, and what you *think* is wrong with it; `SELECT * FROM CUSTOMERS WHERE CUSTOMERS.AGE = '22' OR CUSTOMERS.COUNTRY = 'UK';` – MatBailie Oct 09 '22 at 11:03
  • I am just taking a wild guess: You want a sum of: Amount of rows with people at the age of 22 + amount of rows with people residing in the UK? Then your statement isn't correct at all. I believe [this question](https://stackoverflow.com/q/826365/4934937) should aid you. – maio290 Oct 09 '22 at 11:05
  • 1
    Thank you that's what I was looking for! :D I guess my explanation wasn't clear at all. – OLIVE99 Oct 09 '22 at 11:26

1 Answers1

2

Database Result

You have two customers at the age of 22 and 2 residing in the UK.

This is actually a correct result here - how on earth do you come to the conclusion that you have four people meeting that criteria? If more than one point matches for a database entry, it will only count as one for the result, since it's still the same database entry.

maio290
  • 6,440
  • 1
  • 21
  • 38