All right.
So we have this data in our Instagram clone database.
Now we're going to ask some questions.
And the reason I'm phrasing it that way.
Asking some questions is because that's usually what you're actually doing if you work with sequel as
well.
Some sequel database or any database really even if it's like a mongo D-B or couch D-B post gresse MY
as well.
Any database out there and you have a bunch of data in there.
Yeah some time a lot of the time or just sticking stuff in there.
But when you're actually working with the data and writing queries a lot of what you're doing is asking
questions where you have a motivation you're trying to figure something out whether it's for an ad campaign
or a post-mortem after a campaign.
I know I'm coming back to ads a lot.
It might just be sales like you could be a woodworker.
You make furniture and you want to figure out how much you sold last year because you're compiling your
tax returns or something and you need to figure out the total volume if sold.
Those are the questions you're asking.
So you think in terms of English or whatever language you speak you you think in terms of questions
in a non sexual language like how many acts did I sell last year.
And then you have to translate that to a some a select something from something else and you have to
use some most likely anyway.
So that's how we're going to work here and we'll start out nice and simple in this first video.
Suppose that we want to reward the users who have been around the longest.
So you may have seen something like this on Instagram but other applications you'll sometimes get you
know a coupon or just a thank you email.
You know thanks for being loyal over our five years or however long we've been around.
So all we want to do is reward our users who've been around the longest and to do that we need to find
the five oldest users the users who have been around the longest.
So this one is should be simple not crazy.
We don't need to work with many tables.
Short video.
Try this on your own the video of course.
And in like three seconds I'll be right back.
And I'm back.
So to do this it's just a matter of basically selecting start from users and then we just want to order
them based off of the date that they were created the date they joined and then limit it to five.
So if we hop over what I'll do is make a new file new file where are you and others call it solutions
as well.
And in here the first one is just finding the numbers here so it's easier for you when you are looking
at this finding 5 oldest users and we know it's going to be a select something from users.
And if we start there you can see we've got 100 users which is one thing I wanted to point out 100 users
is not very much but I kept it at 100 because basically the formula that I imprecisely came up with
for how often users are commenting and posting and liking and tagging it grows exponentially depending
on how many users you have.
So having a hundred users we still have you know almost 20000 records for everything else.
And I upped it to 200 or I tried a thousand users at one point.
It really started going crazy and our queries take a lot longer.
So I decided not to do that.
But if you want to try it could be fun too if you feel comfortable writing code to insert a bunch of
users do that in javascript or Python or whatever language you like.
But for now 100 users it's just interesting to note how much data we get even with just a hundred users.
If the average person is posting you know X number of times and then we get certain celebrities who
post all the time.
Not to mention people who are liking all the time and we get bots who like every single photo.
Things quickly grow so select start from users but we want to order by and our field is called created
at right there.
So just order by created.
And if we just do it this way you'll notice that at the bottom we have today's date basically roughly
today state.
And then if we scroll up we've got the oldest one so we've only been around for a little bit about a
year.
According to the data that I created.
So what we'll do is just limit 5.
And there we go.
That's all we need.
So nice and simple for this one.
I want to start off with some review but don't worry if this felt way too easy it's good that's good.
We're going to move on and get into some more exciting slash potentially nastier territory.
All right.