Fields aren't always named in a way that's useful. To fix that, there's the AS keyword.
- It's a little bit subtle, but the names of the fields that we're getting back when we make a query and subsequently the name of the fields we get in a program or something we'd write, are the names of fields or expressions that we put into the statement to begin with. Usually this makes sense, but sometimes if we have a little bit of a lengthy way of creating a field, or want to be more clear in our output, we can change the returned name of the field with the as keyword. Let's take a basic look at that with a statement that will get us the first name and last name of the participants in our people table.
I'll write select. First name. Last Name. From people. Okay, that's a result that we've seen before. Notice how the column headers here are the same as the field names that I asked for. First underscore name. Last underscore name. And if I transform the name a little bit, say we'll make the last name uppercase, the column header changes to match.
And that can be helpful if you want to see what you asked for specifically. But, when you're working with this output in a program, it can be a lot easier to give it a more friendly name. I'll add as and a short name I want to refer to this field as instead. Let's call it surname. This is called an alias. And it becomes the header of the column in the output. This name should have no spaces in it, or if you want to use spaces, you need to wrap up the name in apostrophes. But your developers will appreciate having fields without spaces or special characters in them.
So it's a good idea to keep names without spaces.
- Name the predicate of the following statement: SELECT EyeColor, Age FROM Student WHERE FirstName = 'Tim' ORDER BY LastName ASC;
- Explain what to use to enforce the order in which an expression must be evaluated if the WHERE clause contains multiple expressions to evaluate.
- Identify the best option to join two tables in a database to be able to display data from both.
- List a data type that is not numeric.
- Determine the result of running the following statement on a table containing columns col_1 and col_2:
- INSERT INTO Box (col_1, col_2) VALUES ('A', 'B'), ('A', 'B'), ('A', 'B'), ('A', 'B');
- Determine the best approach of deleting Jon Ramirez (ID 3452) from a Student table.