Download presentation
Presentation is loading. Please wait.
Published byQuentin Oliver Modified over 9 years ago
1
SQL and Conditions Speaker notes will provide additional information!
2
SQL Queries A query retrieves specified information from a database. In SQL, the WHERE clause is used to specify the conditions of the query. For this slide, I will query the payroll table called first_pay that was created in the create presentation. PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 SQL> SELECT * 2 FROM first_pay 3 WHERE jobcode = 'CI'; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 5555 Richard Jones CI 30-OCT-92 50000 2000 The WHERE clause specifies the condition of the query. In this case we want all rows/records where the jobcode = ‘CI’. NOTE: CI is enclosed in single quotes because it is a string literal.
3
SQL queries PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 This query has the criteria of bonus = 2000. This means, the developer only wants to see records where this criteria is true. Note: Because 2000 is a numeric literal, it is not enclosed in quotes.
4
SQL queries PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL> SELECT * 2 FROM first_pay 3 WHERE salary >= 40000; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 All rows/records that meet the criteria of salary greater than or equal to 40000 are shown. This means the record for Susan Ash is not included because her salary is 25000. Note also that the query could have been done with salary >= 40000.00 since the salary field can contain two decimal places.
5
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL queries SQL> SELECT pay_id, name, jobcode, salary 2 FROM first_pay 3 WHERE jobcode <= 'CM'; PAY_ NAME JO SALARY ---- -------------------- -- --------- 1111 Linda Costa CI 45000 3333 Susan Ash AP 25000 4444 Stephen York CM 42000 5555 Richard Jones CI 50000 In this query, only the columns/fields specified in the SELECT are shown. The condition is to test jobcode which was described as CHAR(2) against the string literal CM. This requires that CM is enclosed in single quotes. The query will show all records where the code is less than CM. This includes AP and CI but note that rows/records with jobcode IN are not displayed.
6
SQL> SELECT * 2 FROM donor 3 WHERE yrgoal IS NULL; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT ----- --------------- --------------- ---------- -- ----- --------- --------- ------------ 22222 Carl Hersey 24 Benefit St Providence RI 02045 03-JAN-98 Susan Jones IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT ----- --------------- --------------- ---------- -- ----- --------- --------- ------------ 11111 Stephen Daniels 123 Elm St Seekonk MA 02345 03-JUL-98 500 John Smith 12121 Jennifer Ames 24 Benefit St Providence RI 02045 24-MAY-97 400 Susan Jones 22222 Carl Hersey 24 Benefit St Providence RI 02045 03-JAN-98 Susan Jones 23456 Susan Ash 21 Main St Fall River MA 02720 04-MAR-92 100 Amy Costa 33333 Nancy Taylor 26 Oak St Fall River MA 02720 04-MAR-92 50 John Adams 34567 Robert Brooks 36 Pine St Fall River MA 02720 04-APR-98 50 Amy Costa SQL queries This example looks at a previous discussed table called donor which contains a null value in the third row/record under the column/field YRGOAL. The IS NULL test will find all rows/records where yrgoal is NULL.
7
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL queries SQL> SELECT pay_id, name, jobcode, salary 2 FROM first_pay 3 WHERE jobcode > 'CI' AND salary < 45000; PAY_ NAME JO SALARY ---- -------------------- -- --------- 2222 John Davidson IN 40000 4444 Stephen York CM 42000 This query has two criteria in an AND relationship. Records that meet the criteria jobcode > ‘CI’ have the jobcode shown above in green. Records that meet the criteria salary < 45000 are shown above in blue. Only records that meet both criteria are shown below. The last record with the jobcode of IN does not meet the salary criteria so it is not shown below. The third record with the salary of 25000 does not meet the jobcode criteria so it is not shown below. The second and fourth records meet both criteria and therefore are displayed.
8
AND relationship JOBCODE > CI SALARY < 45000 Display the row/record Logic for: IF JOBCODE > ‘CI’ AND SALARY < 45000 then display the record Y YN N
9
SQL queries - AND SQL> SELECT * 2 FROM first_pay 3 WHERE startdate >= '01-JAN-96' AND startdate <= '31-DEC-99'; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 4444 Stephen York CM 03-JUL-97 42000 2000 PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. This shows an AND query where both tests are on the same column/field. This query looks for all start dates that are greater than or equal to the first day of 96 AND less than or equal to the last date in 99.
10
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL queries SQL> SELECT pay_id, name, jobcode, salary 2 FROM first_pay 3 WHERE jobcode > 'CI' OR salary < 45000; PAY_ NAME JO SALARY ---- -------------------- -- --------- 2222 John Davidson IN 40000 3333 Susan Ash AP 25000 4444 Stephen York CM 42000 6666 Joanne Brown IN 48000 This query has two criteria in an OR relationship. Records that meet the criteria jobcode > ‘CI’ have the jobcode shown above in green. Records that meet the criteria salary < 45000 are shown above in blue. Records that meet either criteria are displayed below. Record 1 and record 5 do not meet either criteria so they do not display. Record 2 and record 4 meet both criteria so they display. Record 3 meets the salary criteria so it displays. Record 6 meets the jobcode criteria so it displays.
11
OR relationship JOBCODE > CI Logic for: IF JOBCODE > ‘CI’ OR SALARY < 45000 then display the record. NOTE: If the answer to either question is true the logic goes to the box that displays the row/record. YN SALARY < 45000 Display the row/record YN
12
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. This shows an OR query where both tests are on the same column/field. This query looks for all start dates that are greater than or equal to the first day of 96 which will find dates in the 19 hundreds greater than that date OR less than or equal to the specified date in 00 which will find all dates up to the first day of 2000. As you can see, it finds the correct dates from the table. SQL> SELECT * 2 FROM first_pay 3 WHERE startdate >= '01-JAN-96' OR startdate <= '31-DEC-00'; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 SQL queries - OR
13
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL queries - AND OR The RULE is that AND is resolved before OR. That means that the conditions around the AND are grouped together. In this case, that means that the condition after the OR stands alone. This code says: bonus = 2000 AND jobcode = ‘IN’ OR just jobcode = ‘CI’. The results are consistent with this interpretation. NOTE: the second record with bonus = 1500 and jobcode = ‘IN’ did not list while the first record with bonus = 1000 and jobcode = ‘CI’ did list. This is because the second record was controlled by the two conditions with the AND while the first record was controlled by only the one condition after the OR. SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000 AND jobcode = 'IN' OR jobcode = 'CI'; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000
14
AND, OR relationship Bonus = 2000 YN Jobcode = CI Display the row/record YN SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000 AND jobcode = 'IN' OR jobcode = 'CI'; YJobcode = IN N
15
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL queries - AND OR The RULE is that AND is resolved before OR. That means that the conditions around the AND are grouped together. If the developer wants to change the order of resolution, parenthesis can be used. Information inside parenthesis is resolved first. With the parenthesis, the code reads bonus = 2000 AND either jobcode = ‘IN’ OR jobcode = ‘CI’. This means that bonus has to be 2000 in all cases AND the jobcode has to be either IN or CI. Because of the parenthesis, the OR is resolved first and thereby grouped. When combined with the AND we have the requirement that bonus = 2000 AND either of the OR conditions. The requirement of bonus = 2000 eliminates records 1, 2 and 3. The requirement that jobcode = IN or CI eliminates record 4. Only record 5 and 6 are shown. The results are consistent with this code. SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000 AND (jobcode = 'IN' OR jobcode = 'CI'); PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000
16
AND, OR relationship Bonus = 2000 YN Display the row/record YJobcode = IN N SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000 AND (jobcode = 'IN' OR jobcode = 'CI'); Jobcode = CI Display the row/record YN
17
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000 AND (salary >= 50000 OR jobcode = 'IN'); PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 AND, OR relationship In this example, bonus must be = to 2000 and either salary must be greater than or equal to 50000 or jobcode must be equal to IN. The OR in parenthesis got resolved and combined with the AND to make bonus = 2000 AND either salary >=50000 OR jobcode=‘IN’.
18
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL> SELECT * 2 FROM first_pay 3 WHERE (bonus = 2000 OR bonus = 1000) AND (jobcode = 'CI' OR jobcode = 'CM'); PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 AND, OR relationship In this example the information within the two sets of parenthesis is resolved first and then the results are combined with the AND. Bonus has to be 2000 or 1000 AND jobcode has to be CI or CM. Only results that have the correct bonus combined with the correct jobcode will display. Records 2 and 3 are eliminated because they do not have one of the correct bonus values. Record 6 is eliminated because it does not have one of the correct jobcode values.
19
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. AND, OR relationships SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000 AND jobcode = 'CI' OR bonus = 500 AND jobcode = 'AP'; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 3333 Susan Ash AP 05-FEB-00 25000 500 5555 Richard Jones CI 30-OCT-92 50000 2000 In this example I want bonus to be 2000 and jobcode ‘CI’ OR I want bonus to be 500 and jobcode ‘AP’. Because ANDs get resolved before ORs, no parenthesis are required. The bonus =2000 and jobcode = CI are grouped when the first AND is resolved and the bonus = 500 and jobcode = AP are grouped when the second AND is resolved. The OR then asks if the first group is true or the second group is true. If either group is true the results get displayed.
20
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL queries - NOT SQL> SELECT * 2 FROM first_pay 3 WHERE NOT bonus = 2000 AND salary > 40000; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 This is looking for NOT bonus = 2000 and it is also looking for salary > 45000. SQL> SELECT * 2 FROM first_pay 3 WHERE bonus = 2000 AND NOT salary > 45000; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 4444 Stephen York CM 03-JUL-97 42000 2000 This is looking for bonus = 2000 and a salary that is NOT greater than 45000.
21
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. SQL queries SQL> SELECT * 2 FROM first_pay 3 WHERE NOT (bonus =2000 AND salary > 40000); PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 This is looking for NOT the combination of bonus = 2000 and salary > 40000. Three records meet this criteria. SQL> SELECT * 2 FROM first_pay 3 WHERE NOT (bonus = 2000 AND salary > 45000); PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 The 2 records that do not display have a bonus = 2000 AND a salary > 45000. The records that display do NOT meet that criteria.
22
SQL queries Summary: The rules for working with NOT, AND, OR NOT is resolved first AND is resolved next OR is resolved last Parenthesis can be used to change the order because things within parenthesis are resolved before things that are not in parenthesis.
23
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. between SQL> SELECT * 2 FROM first_pay 3 WHERE salary BETWEEN 40000 AND 50000; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 The BETWEEN operator allows the developer to ask for records between two points, therefore asking for a range. NOTE: The between is inclusive meaning it includes the two end points that are specified as meeting the criteria.
24
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. in SQL> SELECT * 2 FROM first_pay 3 WHERE startdate IN ('03-JUL-97', '05-FEB-00', '30-OCT-92'); PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 SQL> SELECT * 2 FROM first_pay 3 WHERE bonus IN (1000, 2000); PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Two examples of the IN clause. In both cases only records that match the specification in the IN are displayed.
25
PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 2222 John Davidson IN 25-SEP-92 40000 1500 3333 Susan Ash AP 05-FEB-00 25000 500 4444 Stephen York CM 03-JUL-97 42000 2000 5555 Richard Jones CI 30-OCT-92 50000 2000 6666 Joanne Brown IN 18-AUG-94 48000 2000 Table being used is first_pay. like SQL> SELECT * 2 FROM first_pay 3 WHERE name LIKE 'Jo%'; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 2222 John Davidson IN 25-SEP-92 40000 1500 6666 Joanne Brown IN 18-AUG-94 48000 2000 In this example, I am looking for names starting with Jo. I do not care what the rest of the letters are, so I use the %. % means any number of letters can follow. SQL> SELECT * 2 FROM first_pay 3 WHERE startdate LIKE '___J%'; PAY_ NAME JO STARTDATE SALARY BONUS ---- -------------------- -- --------- --------- --------- 1111 Linda Costa CI 15-JAN-97 45000 1000 4444 Stephen York CM 03-JUL-97 42000 2000 In this case I put the underscore 3 times followed by the J and the %. This indicates that specifically I am skipping 3 characters, then I want a J and then I don’t care how many characters follow.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.