Generate test 2 SQL queries for each of the following tasks
Generate & test 2 SQL queries for each of the following tasks:
A) the SQL statement needed to perform the stated task with the traditional approach.
B) the SQL statement needed to perform the stated task with the JOIN keyword
Apply table aliases in all queries.
Determine which orders haven\'t yet shipped and the name of the customer who placed the order. Sort the results by the date on which the order was placed.
Solution
To write any we query we need to know the table structure, so here I will use a simple and basic scenario of Customer placing order and make tables as
CUSTOMER
ORDER
Now below are the two queries to get orders which havent been shipped
A) select t1.order_id, t2.customer_id, t2. name from ORDERS t1, CUSTOMER t2 where t1.shipping_date=\"\" and t2. customer_id=t1.customer_id order by order_date desc
B) select t1.order_id, t2.customer_id, t2.name from product t1 inner join sales t2 on t2. customer_id=t1.customer_id where t1.shipping_date=\"\" order by order_date desc
| customer_id | name | address |
