1 / 7

Common SQL Misconceptions

Common SQL Misconceptions. SELECT cname FROM customers, orders WHERE pid = ‘p02’;. This is not necessarily the name of customers that ordered p02. It is printing a name of a customer if somebody ordered p02. Name of customers if there exists an order with ‘p02’.

rafe
Télécharger la présentation

Common SQL Misconceptions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Common SQL Misconceptions

  2. SELECT cname FROM customers, orders WHERE pid = ‘p02’; This is not necessarily the name of customers that ordered p02. It is printing a name of a customer if somebody ordered p02. Name of customers if there exists an order with ‘p02’

  3. SELECT cid FROM orders WHERE pid = ‘p02’ and pid = ‘p04’; FOR EACH ROW OF IF pid = ‘p02 and pid = ‘p04 display cid No rows selected

  4. Select cid from orders where pid <> ‘p02’; Cid of customers that one of their orders was not ‘p02’ Tiptop (c001) satisfies this criteria NOT =

  5. DIVISION IN SQL name of customers who ORDERED ALL PRODUCTS select ALL customers (cid) where not exists a product that he has not ordered

  6. DIVISION IN SQL • SELECT cname FROM customer c WHERE NOT EXISTS (SELECT * from PRODUCTS p WHERE NOT EXISTS (SELECT * FROM orders o WHERE c.cid = o.cid AND p.pid = o.pid ));

  7. 3 most expensive products • Name of products where not exists 3 other products that are cheaper than that product SELECT pname from products WHERE NOT EXISTS (SELECT ……..)

More Related