The SELECT and FROM statements are fundamental SQL commands used to retrieve data from databases; SELECT specifies which columns to retrieve (using * for all columns or specific column names separated by commas), while FROM indicates the table to query from, and multiple queries must be separated by semicolons.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Select and From in PostgreSQLAdded:
What's going on everybody? Welcome back to another video. Today we are continuing our Postgra SQL series. This is the very first lesson where we actually start querying data and we're starting with the select and the from statement. Now these are some of the most important ones because they select the data and they choose where that data is coming from. These are very important concepts. They're going to be in every single SQL query you write basically ever unless you're doing something like create table. But if you're querying data, you're going to have a select and from that's just a fact. So understanding these concepts will last you a lifetime. So let's go ahead and take a look at how we can query this data. Now we already created our tables in the last lesson. If you haven't done that already, I will leave a link to this right here. This is just our script for creating our tables and inserting our data. That's it. I will leave a link to this down below where you can download it from GitHub. Super easy. You just run it and then you're good to go.
Now let's actually get into the lesson.
So, what we need to do first is we need to write out select. And if you read that and you said something is wrong, I'm really proud of you. You're probably already ahead of the game and you know what's wrong here. Typically, when we have these commands in SQL, we write them in all caps. Now, it doesn't have to be. The query will technically run perfectly fine if it's all in lowercase, but it's kind of an unwritten rule of formatting your queries to have the commands in all caps. Now, I'm going to be doing that for 99% of the queries in this lesson. You don't have to. You can be a renegade and you can just do what you want, but that's what we're going to do. Now, let's go ahead and we're going to do select star. Now, what star means is it means everything. This means that if we select our character info or our planets or our ships, it's going to give us all the columns and all the rows of data. Now, this can be a little bit trickier as you start working with huge amounts of data because just selecting everything from a table could take minutes or, you know, an hour if you have a ginormous data set that'll just take forever to return. But we're going to select everything. Then we're going to go to the next row. And this is typically how you format a SQL query.
Then we're going to write our next one, which is from. So we're selecting everything. But where are we actually selecting it from? We have to specify.
So let's start with our character info table. So, we're going to say character_info.
And that's it. Select everything from character info. Let's go ahead and execute the script. And just like that, it says it ran successfully. And it's returned all of our columns in all of our rows of data. Really briefly, let's just look at these columns. We have character ID, character name, species, planet ID, ship ID, estimated net worth, if they have both arms, and their birth date. So this is our data, right? We have these columns and in each column we have different rows. That's each of these 1 2 3 4 all the way down to 12.
Now when we're selecting from something, we can specify what we want to select.
Now there are a lot of different things included in the series, but even just in the select statement, there's a lot of things that we can do. For example, if we don't want to select everything, we don't want all of our columns, we can get rid of that star and we can specify the columns that we do want. For example, let's pull up the character name and we can actually include multiple column names. All we have to do is separate it by a comma. So, we're going to do character name and then we'll do this is going to take a while.
Estimated net worth. Let's go ahead and run this.
And this looks perfect. So now we have specified different columns that we want. And in our output, that's all we have. Now let's come right down here.
We're going to go below it. Because when I'm writing SQL queries, I typically don't just have one in here. I have multiple. I have three, four, five, six queries. And as it gets more advanced, they're kind of building on each other with temporary tables and CTEs and all these different things. It gets very complex. And so I typically don't just have one query. I have multiple. So, let's come down here and let's select everything from a different table. So, we're going to do our ships table. So, I'm going to do select everything from ships. Now, this looks great, right?
Let's go ahead and run this. Uh-oh.
There is an error. And the error is not obvious at first. In fact, when I was first learning SQL many years ago, I was really confused about this. In a SQL editor, you can't have two queries run at the same time unless you have them separated. And you do that using a semicolon. So now that it has a semicolon between this code and this code, I'm calling it code, but it's, you know, just a query. Let's go ahead and execute this. And now we get our output.
So it ran successfully. But you'll notice we only have one output down here. And that's fine. If we want to specify just this one, we can highlight over it and then we can run it and it's going to run this query instead. If we run the entire thing, it's just going to run the last query. So, right here. Now, typically at the end of all my queries, I put a semicolon just by default just in case I do want to write something beneath it, but that's just extra information. I'm throwing stuff at you, but just extra information in case you want it. Let's bring this down a little bit. Something I do in the select statement a lot is I create new columns.
And this is very very common. Let's copy this. And I'm going to bring this right down here. And I'm just going to say select everything. And I only want to run this one. So let's go ahead and do that. Let's say I want to take their estimated net worth and I just want to multiply it by something. That would be something I can do in the select statement. So, let's take estimated. And actually, let me copy this because I don't trust my uh spelling skills here.
But I'm going to do a comma. And now we're going to do something. I'm going to take the estimated net worth and I'm going to do a star two. That's going to take the estimated net worth and it's going to multiply it times two. Now, let's go ahead and run this.
And right here, you'll see there's 150,000. Now, it's 300,000. You're also going to notice that there is no column name. It's question mark column question mark and that is not helpful. So what we can actually do in the select column is use an alias. Now an alias just renames a column to something else. So what we're going to do is we're going to say as and we can say double the worth.
And this is going to rename this column as double the worth. Let's go ahead and run this. And there we go. So, we renamed that column to double worth. And now we have estimated net worth and double their worth. So, we're able to perform calculations in the select statement as well. Now, we don't have to do that with just this column because it didn't have a column name. We could do that with anything. So, if we ran this query up here, we could rename this one.
We could say as name. And if we run this one again, you'll see right down here now it says name. Now this gets really helpful the more advanced we get. So when we get to things like subqueries, CTE, window function, these are things where aliasing, not just in the select statement, but also in the from statement, aliasing becomes a lot more important. So we'll get to that in a future lesson to dive more into the advanced kind of pieces of aliasing, but we won't in this lesson. By now, you should feel really comfortable using select and from. Go ahead and try it out. Mess around with it. Select different tables, select different columns. And in the next lesson, we're going to start looking at the where statement where we can start filtering our data. If you learned anything in this lesson, be sure to like and subscribe, and I will see you in the next video.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 viewsβ’2026-05-28
How agent o11y differs from traditional o11y β Phil Hetzel, Braintrust
aiDotEngineer
450 viewsβ’2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanationπ―β
LearnwithSahera
1K viewsβ’2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 viewsβ’2026-05-29
Search Algorithms Explained in 60 Seconds! π€π¨
samarthtuliofficial
218 viewsβ’2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 viewsβ’2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 viewsβ’2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 viewsβ’2026-06-01











