Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
You use literal values for a lot of purposes for example when you add or update rows to a table, you'll often use literals for the new values. Literal strings in MYSQL deserve some attention because there are some ways in which they can be different from the SQL standard. For example, I say select hello world with the single quotes around the string and a semicolon, press Go, we get hello world. So this is standard SQL and standard SQL literal string.
Has single quotes and the characters are inside of the single quotes. Now, if I want to concatenate strings in MYSQL, you can do that like this. And this will give me the same result. Press Go, and that's exactly the same result. Now, you notice what we have here is we have three strings. One string there, another string here which is a comma and a space, and another string here with the word world. So, those are three separate strings, each in single quotes and just separated by spaces like this.
And in MySQL that with concatenate the strings and it's really important to note that this is not standard SQL. You'll see this a lot in MySQL, but this is not standard SQL and it will not work in other database systems. So here's another thing that will not work in other database systems. But this is also very common in MySQL. And that is using double quotes for the literal strings. You'll notice again we have exactly the same. Result, and here we're using double quotes for the string.
This is legal in MySQL, it's common in MySQL, it does not work in other database systems. It is not standard SQL and I suggest that you don't do this. When you want to use a literal string, I strongly suggest that you just use the single quote marks, because someday you might want to take that SQL and port it to another. Database system and hopefully it'll work. Now if you have a literal string with single quote marks and you want to put something in double quotes you just add the double quotes like this.
And this will work. Now the word world will have double quotes around it. And that works just fine and it's perfectly legal in standard SQL. Now if you want to put single quotes around that string, the standard way to do that is like this. Two single quotes next to each other is interpreted as one single quote inside of the literal string. So here's one single quote inside the literal string. And here's another single quote inside the literal string. And when I press Go.
You see, we get the single quote around the word world. Now, in MYSQL, you can also do this like this with a backslash, and a single quote. That's one single quote, and that's one single quote, and that works, and it get's you exactly the same results. Again, this is not standard. This probably won't work in other database systems. So, literally strings in MYSQL can vary from the standard somewhat. I strongly recommend that you stick to standard strings as much as you can so that your SQL is more portable.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101414 Viewers
61 Video lessons · 88175 Viewers
71 Video lessons · 72028 Viewers
56 Video lessons · 103820 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.