1,102 views
0 votes
0 votes

consider the following table customer:

customer_id  cust_name     city        grade       salesman_id
-----------  ------------  ----------  ----------  -----------
3002         Nick Rimando  New York    100         5001
3005         Graham Zusi   California  200         5002
3001         Brad Guzan    London                  5005
3004         Fabian Johns  Paris       300         5006
3007         Brad Davis    New York    200         5001
3009         Geoff Camero  Berlin      100         5003
3008         Julian Green  London      300         5002
3003         Jozy Altidor  Moscow      200         5007

A SQL Query to display all the customers, who are either belongs to the city New York or not had a grade above 100.

option 1: 

SELECT * 
FROM customer 
WHERE city = 'New York' OR NOT grade>100;

option 2:

SELECT * 
FROM customer 
WHERE city = 'New York' OR grade<100;

my doubt is query 1 using a NOT operator which is the given answer, query 2 is my answer where I'm using < operator, so both queries will produce the same result for given problem???

1 Answer

Best answer
2 votes
2 votes

Both queries will give different results.

A SQL Query to display all the customers, who are either belongs to the city New York or not had a grade above 100 i.e. grade is less than or equal to 100.

It will return the following 3 tuples

customer_id  cust_name     city        grade       salesman_id
-----------  ------------  ----------  ----------  -----------
3002         Nick Rimando  New York    100         5001
3007         Brad Davis    New York    200         5001
3009         Geoff Camero  Berlin      100         5003

Now, coming to your SQL queries, i think first is correct and second is incorrect. Also verified them online.

Second correct query should be :

whereas your second query results in :

which is incorrect!

selected by

Related questions

0 votes
0 votes
1 answer
3
rayhanrjt asked Jan 6, 2023
822 views
Write SQL command to find DepartmentID, EmployeeName from Employee table whose average salary is above 20000.
2 votes
2 votes
1 answer
4
Subhrangsu asked Jun 18, 2022
458 views
Write SQL query to show all employees hired on June 4,1984 (non-default format)emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)