Query a SQL database

Query a SQL database


So let’s move a bit to progress a little
more programming at the question so I do want to start you
off with a SQL question.>>Okay.>>Let’s say we have this table and
maybe I should writer and if you want to write it,
but here feel free to.>>Okay.
>>Let’s say you have a table and list it was called cards right and this
table is going to have several rows. The first one is going to be an i.d. Which is just an integer. The second one is going to be
a make of the other vehicle. Where you can be a character. Ok.
Or a set of characters right so
the next one to be the model. Of the vehicle. Character as well.>>Do you mean like a stream?>>I think okay yeah string. Yeah.>>Okay so. Okay I’ll remember [LAUGH]
>>And the next phase will be how many
cylinders this is ripple have? Preferably is an Integer. And lastly the horse power. Of the car is also an integer. So, okay, so what I would like you to
do is, to write a simple query that will give me the three vehicles with
the highest number of horsepower, that have more than
six cylinders in them. Okay, let me, say that again so
that I can write it down. The three.>>The three vehicles.>>Vehicles.>>That have the highest horsepower.>>Highest horsepower. Okay.>>But at least six cylinders.>>Okay Okay. So I’m assuming that in
my table I could have I guess what I’m wondering is,
are we talking about vehicles, as in, with separate id? Or are we thinking about types
of vehicle, like make and model. Could there be more than one
car with the same make and model, and presumably, the same
number of cylinders and horsepower?>>No, no, so this would be different. Yeah
>>Okay, Okay.>>This is just information
about to make a model.>>.Okay Okay so like this would be
specified by like make model here.>>Yes exactly.>>Okay cool. Right okay so. This I need to write out the query but
I’m trying to think of the best order so let me think through what I
need to do so this three will be a limit three that will probably
be the last thing in my query.>>Okay.
>>I’ll be selecting make and model from cars where there
are like number of cylinders is greater than or equal to six and
order by i horsepower. And I guess I’ll need to figure out,
it’ll have to be desk descending. Okay.
>>So.>>Yeah.
>>Now I need to put that all together. [LAUGH]
>>[LAUGH] Yeah, that sounds perfect.>>Okay, so select. Make model from cars where Number of cylinders is greater than or equal to six and
then I’m going to order. By horsepower Descending. And then limit three, semi-colon. I’ve run into that problem before. [LAUGH] So
I think that probably does it.>>So return a table,
make model from course. All right there’s six cylinders,
order by the horsepower we want, the high is three, limit three. Yeah.
So that’s excellent.>>Okay.
Great.