Consider the below orders table:Column NameDatatypeConstraintorder_idNumberPKOrder_dateDate Order_modevarchar Customer_idNumber Order_totalNumber(8,2) There is only one customer with the CUST_LAST_NAME column having value Roberts. Which INSERT statement should be used to add a row into the ORDERS table for the customer whose CUST_LAST_NAME is Roberts and CREDIT_LIMIT is 600?Select one:a.INSERT INTO orders ( order_id ,order _date,order_mode , (SELECT customer_id FROM customersWHERE cust_last_name ='Roberts' ANDcredit_limit =600) , order _total )VALUES (1,'10-mar-2007','direct' ,& &customer_id,1000);b.INSERT INTO( SELECT o.order_id,o.order,o.order_mode,c.customer_id,o.order_totalFROM orders o, customers c WHERE o.customer_id = c.customer_id AND c.cust_last_name='Roberts' and c.credit_limit =600)VALUES (1,'10-mar-2007','direct' ,& &customer_id,1000);FROM customersWHERE cust_last_name ='Roberts' ANDcredit_limit =600) ,1000 );c.INSERT INTO orders ( order_id ,order _date,order_mode , (SELECT customer_id FROM customersWHERE cust_last_name ='Roberts' ANDcredit_limit =600) , order _total )VALUES (1,'10-mar-2007','direct' ,& customer_id,1000);d.INSERT INTO orders VALUES( 1,'10-mar-2007','direct', (SELECT customer_id FROMcustomers WHERE cust_last_name ='Roberts' ANDcredit_limit =600) ,1000 );
Question
Consider the below orders table:Column NameDatatypeConstraintorder_idNumberPKOrder_dateDate Order_modevarchar Customer_idNumber Order_totalNumber(8,2) There is only one customer with the CUST_LAST_NAME column having value Roberts. Which INSERT statement should be used to add a row into the ORDERS table for the customer whose CUST_LAST_NAME is Roberts and CREDIT_LIMIT is 600?Select one:a.INSERT INTO orders ( order_id ,order _date,order_mode , (SELECT customer_id FROM customersWHERE cust_last_name ='Roberts' ANDcredit_limit =600) , order _total )VALUES (1,'10-mar-2007','direct' ,& &customer_id,1000);b.INSERT INTO( SELECT o.order_id,o.order,o.order_mode,c.customer_id,o.order_totalFROM orders o, customers c WHERE o.customer_id = c.customer_id AND c.cust_last_name='Roberts' and c.credit_limit =600)VALUES (1,'10-mar-2007','direct' ,& &customer_id,1000);FROM customersWHERE cust_last_name ='Roberts' ANDcredit_limit =600) ,1000 );c.INSERT INTO orders ( order_id ,order _date,order_mode , (SELECT customer_id FROM customersWHERE cust_last_name ='Roberts' ANDcredit_limit =600) , order _total )VALUES (1,'10-mar-2007','direct' ,& customer_id,1000);d.INSERT INTO orders VALUES( 1,'10-mar-2007','direct', (SELECT customer_id FROMcustomers WHERE cust_last_name ='Roberts' ANDcredit_limit =600) ,1000 );
Solution
The correct answer is:
d. INSERT INTO orders VALUES( 1,'10-mar-2007','direct', (SELECT customer_id FROM customers WHERE cust_last_name ='Roberts' AND credit_limit =600) ,1000 );
This statement is correct because it correctly uses a subquery to select the customer_id from the customers table where the last name is 'Roberts' and the credit limit is 600. This subquery is used as a value to be inserted into the orders table. The other options are incorrect because they either use incorrect syntax or they attempt to insert a value into a column that does not exist.
Similar Questions
Which one of the following is the correct syntax for an insert statement?
A table has the following 3 columns: (Receipt_No INT PRIMARY KEY AUTO_INCREMENT, Receipt_Date DATETIME, Cust_No INT). To insert data, the INSERT INTO keyword should include how many data columns for the table?Select one:a.None of the answers are correctb.3c.4d.2e.1
A) We have following relation orders(order_id,customer_id,order_date,amount). Create table with Primary Key, otherrelevant constraints in given schema.1) Find out the number of orders for each customer by customer_id and show only customer_id with number of orders above 5.2) Find out the total amount by order_id and order_date.B) Find the sum of a user-inserted number's first and last digits using PL/pgSQL function
Customer Placing the Largest Number of OrdersQuery the customer_number from the orders table for the customer who has placed the largest number of orders.It is guaranteed that exactly one customer will have placed more orders than any other customer.The orders table is defined as follows:ColumnTypeorder_number (PK)intcustomer_numberintorder_datedaterequired_datedateshipped_datedatestatuschar(15)commentchar(200)Sample Inputorder_numbercustomer_numberorder_daterequired_dateshipped_date112017-04-092017-04-132017-04-12222017-04-152017-04-202017-04-18332017-04-162017-04-252017-04-20442017-04-182017-04-282017-04-25Sample Outputcustomer_number3ExplanationThe customer with number '3' has two orders, which is greater than either customer '1' or '2' because each of them only has one order.So the result is customer_number '3'. Follow up: What if more than one customer have the largest number of orders, can you find all the customer_number in this case?Optionsselect customer_numberfrom ( select customer_number, count(*) as cnt group by customer_number) as eorder by e.cnt desclimit 1;select customer_numberfrom ( select customer_number, count(*) as cnt from orders group by customer_number) as eorder by e.cnt desclimit 1;select customer_number select customer_number, count(*) as cnt from orders group by customer_number) as eorder by e.cnt desclimit 1;select customer_numberfrom ( select customer_number, count(*) as cnt from orders group by customer_number) as elimit 1;
Which SQL statement is used to insert new data into a database table?INSERT NEWUPDATE INTOADD TOINSERT INTO
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.