Given a table customer holding customers information and the referee.idnamereferee_id1WillNULL2JaneNULL3Alex24BillNULL5Zack16Mark2Write a query to return the list of customers NOT referred by the person with id'2'. For the sample data above, the result is:nameWillJaneBillZackOptionsselect namecustomerwhere referee_id is null or referee_id <> 2;select referee_idfrom customerwhere referee_id is null or referee_id <> 2;select namefrom customerwhere name is null or referee_id <> 2;select namefrom customerwhere referee_id is null or referee_id <> 2;
Question
Given a table customer holding customers information and the referee.idnamereferee_id1WillNULL2JaneNULL3Alex24BillNULL5Zack16Mark2Write a query to return the list of customers NOT referred by the person with id'2'. For the sample data above, the result is:nameWillJaneBillZackOptionsselect namecustomerwhere referee_id is null or referee_id <> 2;select referee_idfrom customerwhere referee_id is null or referee_id <> 2;select namefrom customerwhere name is null or referee_id <> 2;select namefrom customerwhere referee_id is null or referee_id <> 2;
Solution
The correct query to return the list of customers NOT referred by the person with id '2' is:
select name
from customer
where referee_id is null or referee_id <> 2;
This query works by selecting the 'name' column from the 'customer' table where the 'referee_id' is either null (meaning the customer was not referred by anyone) or not equal to '2' (meaning the customer was not referred by the person with id '2').
Similar Questions
Find the names of the customer that are not referred by the customer with id = 2.Return the result table in any order.The result format is in the following example.
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.Table: Customers.IdName1Joe2Henry3Sam4MaxTable: Orders.IdCustomerId1321Using the above tables as example, return the following:CustomersHenryMaxOptionsselect Name as Customers from Customers not in ( select CustomerId from Orders);select Name from Customers where Id in ( select CustomerId from Orders);select Name as Customers from Customers where Id not in ( Orders);select Name as Customers from Customers where Id not in ( select CustomerId from Orders);
You have a database with a customers table. Here is a partial listing of the records:First_NameLast_NameMichelleSenseAlexisRodriguezFloraSatoYou also have a table of employees. Here is a partial listing of the records:First_NameLast_NameSamuelClementineAlexisRodriguezJabariReddyYou want to create a query that will not return “Alexis Rodriguez” as part of the results. You begin typing your query:SELECT First_Name, Last_Name FROM customers________SELECT First_Name, Last_Name FROM employeesWhat should you type in the blank space between the two queries? (Please type your answer all in upper case. Example: SELECT)
For the following tables:Customers (CustomerID, CustomerName, PhoneNumber, Address)Orders (OrderID, OrderDate, CustomerID)To return the CustomerName and OrderDate that the result must include the customers who have not placed any orders.Which Transact-SQL query should you use?SELECT CustomerName, OrderDateFROM Customers JOIN Orders ON Customers.CustomerID = Orders.CustomerID;SELECT CustomerName, OrderDateFROM Customers RIGHT OUTER JOIN OrdersON Customers.CustomerID = Orders.CustomerID;SELECT CustomerName, OrderDateFROM Customers LEFT OUTER JOIN OrdersON Customers.CustomerID = Orders.CustomerID;SELECT CustomerName, OrderDateFROM Customers CROSS JOIN OrdersON Customers.CustomerID = Orders.CustomerID;
The following SQL is which type of join:SELECT CUSTOMER_T.CUSTOMER_ID, ORDER_T.CUSTOMER_ID, NAME, ORDER_IDFROM CUSTOMER_T, ORDER_TWHERE CUSTOMER_T.CUSTOMER_ID = ORDER_T.CUSTOMER_IDINNER JOINCROSS JOINSELF JOINOUTER JOIN
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.