1 00:00:00,260 --> 00:00:04,390 To recap, SQL or Structured Query Language 2 00:00:04,390 --> 00:00:09,890 is a specialized language to get information or data out of a database. 3 00:00:09,890 --> 00:00:13,400 There are many different database systems such as MySQL, 4 00:00:13,400 --> 00:00:18,050 Microsoft SQL Server, Oracle, PostgreSQL, and SQLite. 5 00:00:18,050 --> 00:00:20,350 All of them use the same language, SQL. 6 00:00:21,390 --> 00:00:25,330 Just like spoken languages, programming languages have their own vocabulary and 7 00:00:25,330 --> 00:00:27,020 grammatical structure. 8 00:00:27,020 --> 00:00:30,840 Programmers refer to this vocabulary and grammar as syntax. 9 00:00:30,840 --> 00:00:34,470 Thankfully, most programming languages have a much smaller vocabulary 10 00:00:34,470 --> 00:00:36,390 than spoken languages. 11 00:00:36,390 --> 00:00:37,500 Though they are few, 12 00:00:37,500 --> 00:00:41,520 the vocabulary words in programming languages are very important. 13 00:00:41,520 --> 00:00:42,915 And we call them key words. 14 00:00:42,915 --> 00:00:48,003 [SOUND] A keyword is a command that you issue to a computer to do a certain thing. 15 00:00:48,003 --> 00:00:51,280 And SQL has its own sets of keywords. 16 00:00:51,280 --> 00:00:56,120 Lines of SQL code are known as a Statement or a Query. 17 00:00:56,120 --> 00:00:59,230 A statement in SQL is like a sentence in English. 18 00:00:59,230 --> 00:01:03,480 A query in SQL is like asking a question in English. 19 00:01:03,480 --> 00:01:09,500 Most queries, no matter how complex, are issued to the database one at a time. 20 00:01:09,500 --> 00:01:14,230 You may hear the issuing of a statement being referred to as running a query, or 21 00:01:14,230 --> 00:01:15,370 executing the SQL. 22 00:01:16,440 --> 00:01:19,802 Let's take a look at a common SQL query. 23 00:01:19,802 --> 00:01:24,530 We'll retrieve all information from the table with the data about books. 24 00:01:24,530 --> 00:01:27,820 Remember, a table is one of the spreadsheet like structures 25 00:01:27,820 --> 00:01:31,460 inside a database made up of rows and columns. 26 00:01:31,460 --> 00:01:36,312 Let's see how we might write a query in English first. 27 00:01:36,312 --> 00:01:41,086 [SOUND] What is all the information we have about each book in the books table? 28 00:01:41,086 --> 00:01:44,642 Now, let's see the SQL syntax to bring back all the information from 29 00:01:44,642 --> 00:01:45,870 the books table. 30 00:01:45,870 --> 00:01:48,850 See those upper case words there, SELECT and FROM? 31 00:01:48,850 --> 00:01:54,170 They are key words or special words reserved for the SQL programming language. 32 00:01:54,170 --> 00:01:58,040 You issue a select command when you want to write a query. 33 00:01:58,040 --> 00:02:00,390 You're asking the database to select or 34 00:02:00,390 --> 00:02:04,450 retrieve some of the information from a particular table. 35 00:02:04,450 --> 00:02:06,650 In this case, it's books. 36 00:02:06,650 --> 00:02:09,980 The asterisk, or the star character, means you want to bring 37 00:02:09,980 --> 00:02:13,690 all of the information in all of the tables' columns back. 38 00:02:13,690 --> 00:02:17,630 I'll show you how to bring back specific columns of information later. 39 00:02:17,630 --> 00:02:21,260 The semicolon at the end of the query is like a period or 40 00:02:21,260 --> 00:02:24,050 a question mark at the end of a sentence or question. 41 00:02:24,050 --> 00:02:29,530 The semicolon lets the database know where the statement ends or terminates. 42 00:02:29,530 --> 00:02:31,740 When we issue the statement to the database, 43 00:02:31,740 --> 00:02:35,970 you can expect all entries in the books table to be returned. 44 00:02:35,970 --> 00:02:39,510 Let's see the results of this query in the SQL playground and 45 00:02:39,510 --> 00:02:40,690 see this query in action. 46 00:02:42,450 --> 00:02:46,280 As you can see, it brings back all information in the books table. 47 00:02:46,280 --> 00:02:48,600 Let's ask another question. 48 00:02:48,600 --> 00:02:52,650 Who are all the users of the library in the patrons table? 49 00:02:52,650 --> 00:02:54,150 We'd use the SELECT keyword, 50 00:02:55,310 --> 00:02:57,280 star, meaning all of the columns, 51 00:02:58,520 --> 00:03:00,960 FROM, and then the table name. 52 00:03:00,960 --> 00:03:04,210 In this case, the table name is patrons. 53 00:03:04,210 --> 00:03:06,880 Don't forget the semicolon to terminate the statement. 54 00:03:07,910 --> 00:03:12,600 Once we execute this query, it will return all patron information. 55 00:03:12,600 --> 00:03:17,733 So generally speaking, writing SELECT * FROM <table name>; 56 00:03:17,733 --> 00:03:22,690 is a query we can use to retrieve all data from any table. 57 00:03:22,690 --> 00:03:25,553 This can be useful for small data sets. 58 00:03:25,553 --> 00:03:30,001 When you have larger data sets like the users of a large social network, or 59 00:03:30,001 --> 00:03:35,098 the orders from a popular e-commerce site, you probably don't want to run queries 60 00:03:35,098 --> 00:03:40,490 like this because it can take a very long time to execute and return the results. 61 00:03:40,490 --> 00:03:44,690 This can slow the performance down for other database users too. 62 00:03:44,690 --> 00:03:48,240 However, the data sets in this course are very small, and 63 00:03:48,240 --> 00:03:52,970 running these types of queries won't have any real performance impact. 64 00:03:52,970 --> 00:03:57,890 Databases have more utility than reporting all the information in one table. 65 00:03:57,890 --> 00:04:01,400 In the next video, I'll show you how to bring back specific columns.