To do that, we use the FROM keyword to specify from which table we want the data. What we really want to do is select values from our data tables. So selecting values such as 'hello' and 100 is not very exciting, nor does it make much sense. Using the FROM clause to select data from tables But don't worry, we'll reiterate the concept by the end of the lesson. What if we wanted to SELECT the literal text string of 'SELECT'? Again, by using the single-quotes, we specify to the interpreter that we want the word "SELECT", literally: SELECT 'SELECT' 'SELECT'Īre you literally tired of seeing the word literal explained over and over? I belabor the point here because not knowing when to use single-quotes – or if you're new to programming in general, the importance concept of computer syntax – will bite you very hard, very soon. The following query would return an error, because it doesn't make sense to the interpreter: SELECT SELECT If it's not obvious by now, the word SELECT has a special meaning to the SQLite interpreter, as it is a keyword in the syntax of the SQLite language. So when I use the term literal, I mean, just the plain, ordinary value that a text string has for humans, rather than the special meaning that it might have for the computer. Without the single-quotes, the SQLite interpreter interprets hello as something non-literal, such as the the name of a column or some other SQLite-specific command. You should get an error message: Error: no such column: hello What happens if you omit the single quotes, as we did in the first example queries with just numbers (e.g. We just enclose the phrase in single quotes, which specifies that we want hello and world again, literally, but as a single string connected with a literal comma and space: SELECT 'hello, world' What if we wanted to select the phrase, 'hello, world'? I re-emphasize the term literal here the previous query selected the literal words 'hello' and 'world', separately. We can specify literal text strings by enclosing a word in single quotes (i.e. The result is just…more values, each in their own column: 100 In SQL syntax, we can specify a series of values to select by separating them with commas note in the example below, it's only the commas that delimit the values whitespace and newlines have no effect. The result of that "query" is simply the number 100, returned as a single column (with a header of 100) and a single row. We asked the database to "select the number 100" and it obliged. Also, text is a lot easier to produce for these tutorials. This is partly to emphasize that whatever graphical client we use is merely a user-friendly shell for the code we execute. The result should look something like this (note that I've left off the semi-colon, which is optional here but is generally used to denote the end of a command):įrom this point on, I’ll be displaying the input and output of these examples as just text, rather than screenshotting the GUI. Then hit the Play button (or better yet, the keyboard shortcut: Ctrl + Return). If you are using the client, DB Browser for SQLite, select the Execute SQL tab and type the following into the first input box: SELECT 100 Open a database file – I'm assuming you've downloaded and unzipped the following file: As a corollary – if you read the excerpt above – this means most what we generally do with SQL databases does not alter the data, i.e. There's not many kinds of statements in SQL, and 95% of our queries will involve using the SELECT statement. A SELECT statement does not make any changes to the database. The result of a SELECT is zero or more rows of data where each row has a fixed number of columns. You can guess what the SELECT statement does: it's what we use to query the database for data. Trying to select from a non-existent table.Trying to select columns without a table.Using the FROM clause to select data from tables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |