Hello in this python programming tutorial we are going to cover the Select operations so as the name suggests, allows us to select stuff basically allows us to select rows at the moment we got these two rows one with the name of for home of the name of the same and only have the information is this. So select allows you to select one row multiple rows, you basically provide some parameter the bare basics is where you select any from you know the table name. And then you can provide some extra stuff as well like a certain condition you can wear key command and other conditions as well. Maybe you can order it, maybe limit how many results you want all of that good stuff. I'm just going to do a simple select query because again, this you know isn't about teaching my SQL because the plenty of resources online by basis about covering how to use the my SQL select query within Python, if you have any questions about this or anything a bit more than feel free to reach out and I will assist you.
So we want to select both of these as the that the latest version, and we go to our code file, pretty simple. Just need to do an SQL query and we have done before, put select and now you just put what you want to select. So you could put you know, stuff like the actual rows, but I'm Asterix is select everything selected within the table. And here is where you can use something like a way command to listen for condition but again, just keeping it simple. I'm going to do the try block again just so to learn the problem. They can be handled accordingly.
So in here, we will print unable to fetch data on able to data, where you got to think, is when actually doing anything to the database. So we don't need to roll anything back rollback is only, like we're not updating or inserting something, and then something's gone wrong. So in here, we just need to do the cursor dot execute. So this is nothing new, execute my SQL, so it just gets this query from you. Now we need to get all the results. So we operate within a variable called results.
And you get the results, simple cursor, dot fetch all and what we'll do a loop over every row that we've got whether that one row or 100 rows will be two in our case, for row results, so for every row, it will get put into row and we'll be able to access each basically column all mentioned, the one credit variable called name, and that's gonna be row zero because as you can see, the first row is name, location, gender, Remember, in computers most things start at zero. And now we're going to do location equals row one, and gender equals row two. And finally we're going to do age again, you don't need to get one of these, you might only get like three of them in this particular point and we get some more later in my only get one, but I'm gonna show you how to get on them.
Now what we're going to do is just do a simple print, print. And we are going to do name, center comma location, colon, comma gender a And now what we need to do is actually specify the variables that we want to put here. Here. Yeah, and here. So location. Age Oh, okay.
So if we said that we should be able to go so now let's run this and see what we get. Now Iris says unable to get data. So let's have a look what's gone wrong. So SQL equals select everything from test table. So that does seem not a problem to me. So with the cursor, dot execute SQL, okay.
I'm unable to get data. So really should not be anything So let's try running it again. Okay. So there was something in here they didn't like. And let's just eliminate that he wasn't the results. So it was not mine.
So something within here it does not look. So what could it be? This needs to be included in brackets. So if I run that again, there we go. Okay, this was a simple syntax error on my part and he was selected all of the roads to the road to only two rows. So that's it for the Select query.
Like I said, this is not a tutorial on you know, the all the facets of my SQL Just had to implement the my SQL select query within Python. If you want to know more about it, the load resources on the my SQL website under the free school and again, just feel free to reach out and I'll help you along your development journey. That's it for this video. Thanks for watching and I look forward to seeing you soon.