tailieunhanh - Using SQL phần 2
Figure : Products where ProductName is like 'Cha%' The next SELECT statement uses the LIKE operator to retrieve products where the ProductName column | Figure Products where ProductName is like Cha The next SELECT statement uses the LIKE operator to retrieve products where the ProductName column is like ABC SELECT ProductID ProductName FROM Products WHERE ProductName LIKE ABC Figure shows the results of this SELECT statement. LIKE ABC matches products with a name that starts with any of the letters A B or C and ends with any number of characters. Figure Products where ProductName is like ABC The next SELECT statement uses the LIKE operator to retrieve products where the ProductName column is like AABC SELECT ProductID ProductName FROM Products WHERE ProductName LIKE AABC Figure shows the results of this SELECT statement. LIKE AABC matches products with names that don t start with any of the letters A B or C and end with any number of characters. Figure Products where ProductName is like AABC The next SELECT statement uses the LIKE operator to retrieve products where the ProductName column is like A-E SELECT ProductID ProductName FROM Products WHERE ProductName LIKE A-E Figure shows the results of this SELECT statement. LIKE A-E matches products with names that start with any of the letters A through E and end with any number of characters. Figure Products where ProductName is like A-E Specifying a List of Values You use the IN operator in a WHERE clause to retrieve rows with columns that contain values in a specified list. For example the following SELECT statement uses the IN operator to retrieve products with a ProductID of 1 2 5 15 20 45 or 50 SELECT ProductID ProductName QuantityPerUnit UnitPrice FROM Products WHERE ProductID IN 1 2 5 15 20 45 50 Here s another example that displays the OrderID column from the Orders table for the rows where the CustomerID column is in the list retrieved by a subquery the subquery retrieves the CustomerID column from the Customers table where the CompanyName is like Fu SELECT OrderID FROM Orders WHERE CustomerID IN SELECT CustomerID FROM Customers .
đang nạp các trang xem trước