From the course: SQL: Data Reporting and Analysis

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Use variables

Use variables

- [Instructor] Now we're going to look at variables. A variable is a user defined keyword that's used to store data and that data might just be a number or a piece of text, a date, but it could also be a whole result set from a query. So with variables there are two obvious ways that you could use them, one is as a filter which is what we're going to look at first. And then the other way is to store results into a variable with select into, and the reason, looking first at the using a variable as a filter, the reason you would want to use a variable is if you've got a particularly long query and you are making reference to an ID say, which is liable to change and perhaps you're making reference to it multiple times then with a variable, you can just update the variable in one place at the top of your code, nice and neat, and you are done. You don't have to go sifting through your code. So in MySQL, to declare a variable…

Contents