1) Please fix the following code. create database spring18_midterm; use spring18
ID: 3738225 • Letter: 1
Question
1) Please fix the following code.
create database spring18_midterm;
use spring18_midterm;
CREATE TABLE phone_book (id INT NOT NULL AUTO_INCREMENT, firstnamevarchar(100) NOT NULL, surname varchar(100) NOT NULL, phone varchar(100) NOT NULL, primary key(id));
GRANT SELECT, INSERT, UPDATE ON fall12_tests.phone_book TO 'frank'@'localhost';
INSERT INTO phone_book (fristname, surname, phone ) VALUES ('Ann', 'Green', '(770) 567-5566'), ('Bob', 'Red', '(678) 678-6787');
SELECT * from phone_book;
2) correct the following errors
3)Correct the following errors
Color table color Black Blue Green Red Products table: sku product_description color Red Blue NULL 1 Ba11 Bike 3 Tent Query: SELECT c.color FROM Colors ASC WHERE C.color NOT IN (SELECT P.color FROM Products AS P) Result: color (0 row (s) affected)Explanation / Answer
Solution:
1)
The correct query is:
CREATE TABLE phone_book (id INT NOT NULL AUTO_INCREMENT, firstname varchar(100) NOT NULL, surname varchar(100) NOT NULL, phone varchar(100) NOT NULL, primary key(id));
rest of the queries are correct.
2)
This query is also correct and it should be printing
Black
Green
3)
The order of WHERE, HAVING ORDERBY AND GROUP BY in not correct in the given code the proper order should be
WHERE filtering the rows
GROUP BY combining the two rows
HAVING dividing into groups
ORDER BY arranges the remaining rows/groups
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.