1 00:00:00,000 --> 00:00:04,150 Hello and welcome to retrieving data with a SELECT statement. 2 00:00:04,150 --> 00:00:06,900 In this video, we will learn about retrieving data from 3 00:00:06,900 --> 00:00:10,890 a relational database table by selecting columns of a table. 4 00:00:10,890 --> 00:00:12,465 At the end of this lesson, 5 00:00:12,465 --> 00:00:16,035 you will be able to retrieve data from a relational database table, 6 00:00:16,035 --> 00:00:17,955 to find the use of a predicate, 7 00:00:17,955 --> 00:00:22,530 identify the syntax of the SELECT statement using the WHERE clause, and 8 00:00:22,530 --> 00:00:27,400 list the comparison operators supported by a relational database management system. 9 00:00:27,400 --> 00:00:30,600 The main purpose of a database management system, 10 00:00:30,600 --> 00:00:35,370 is not just to store the data but also facilitate retrieval of the data. 11 00:00:35,370 --> 00:00:40,795 So, after creating a relational database table and inserting data into the table, 12 00:00:40,795 --> 00:00:42,385 we want to see the data. 13 00:00:42,385 --> 00:00:45,945 To see the data, we use the SELECT statement. 14 00:00:45,945 --> 00:00:49,820 The SELECT statement is a data manipulation language statement. 15 00:00:49,820 --> 00:00:56,055 Data Manipulation Language statements or DML statements are used to read and modify data. 16 00:00:56,055 --> 00:00:58,655 The SELECT statement is called a query, 17 00:00:58,655 --> 00:01:04,470 and the output we get from executing this query is called a result set or a result table. 18 00:01:04,470 --> 00:01:09,305 In its simplest form, a SELECT statement is select star from table name. 19 00:01:09,305 --> 00:01:11,780 Based on the book entity example, 20 00:01:11,780 --> 00:01:13,350 we would create the table using 21 00:01:13,350 --> 00:01:18,000 the entity name book and the entity attributes as the columns of the table. 22 00:01:18,000 --> 00:01:20,990 The data would be added to the book table by adding 23 00:01:20,990 --> 00:01:23,955 rows to the table using the insert statement. 24 00:01:23,955 --> 00:01:29,785 In the book entity example, select star from book gives the result set of four rows. 25 00:01:29,785 --> 00:01:34,345 All the data rows for all columns in the table book are displayed. 26 00:01:34,345 --> 00:01:38,510 In addition, you can also retrieve all the rows for all columns by 27 00:01:38,510 --> 00:01:42,680 specifying the column names individually in the SELECT statement. 28 00:01:42,680 --> 00:01:45,985 You don't always have to retrieve all the columns in a table. 29 00:01:45,985 --> 00:01:48,615 You can retrieve just a subset of columns. 30 00:01:48,615 --> 00:01:52,125 If you want, you can retrieve just two columns from the table book. 31 00:01:52,125 --> 00:01:55,695 For example book_id and title. 32 00:01:55,695 --> 00:02:01,655 In this case, the select statement is select book_id, title from book. 33 00:02:01,655 --> 00:02:06,220 In this case, only the two columns display for each of the four rows. 34 00:02:06,220 --> 00:02:09,025 Also notice that the order of the columns displayed 35 00:02:09,025 --> 00:02:11,880 always matches the order in the SELECT statement. 36 00:02:11,880 --> 00:02:17,900 However, what if we want to know the title of the book whose book_id is B1. 37 00:02:17,900 --> 00:02:20,590 Relational operation helps us in restricting 38 00:02:20,590 --> 00:02:23,680 the result set by allowing us to use the clause WHERE. 39 00:02:23,680 --> 00:02:26,565 The WHERE clause always requires a predicate. 40 00:02:26,565 --> 00:02:31,490 A predicate is conditioned evaluates to true, false or unknown. 41 00:02:31,490 --> 00:02:35,090 Predicates are used in the search condition of the WHERE clause. 42 00:02:35,090 --> 00:02:39,950 So, if we need to know the title of the book whose book_id is B1, 43 00:02:39,950 --> 00:02:45,235 we use the WHERE clause with the predicate book_id equals B1. 44 00:02:45,235 --> 00:02:52,245 Select book_id title from book where book_id equals B1. 45 00:02:52,245 --> 00:02:54,830 Notice the result set is now restricted to 46 00:02:54,830 --> 00:02:57,880 just one row whose condition evaluates to true. 47 00:02:57,880 --> 00:03:03,200 The previous example used comparison operator equal to in the WHERE clause. 48 00:03:03,200 --> 00:03:05,850 There are other comparison operators supported by 49 00:03:05,850 --> 00:03:09,215 a relational database management system: equal to, 50 00:03:09,215 --> 00:03:11,430 greater than, less than, 51 00:03:11,430 --> 00:03:13,280 greater than or equal to, 52 00:03:13,280 --> 00:03:17,050 less than or equal to, and not equal to. 53 00:03:17,050 --> 00:03:21,515 Now you can retrieve data and select columns from a relational database table, 54 00:03:21,515 --> 00:03:23,385 define the use of a predicate, 55 00:03:23,385 --> 00:03:27,730 identify the syntax of the SELECT statement using the WHERE clause, and 56 00:03:27,730 --> 00:03:32,695 list the comparison operators supported by a relational database management system. 57 00:03:32,695 --> 00:03:35,620 Thanks for watching this video.