Reader small image

You're reading from  Learn SQL using MySQL in One Day and Learn It Well

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781836205678
Edition1st Edition
Right arrow
Author (1)
Jamie Chan
Jamie Chan
author image
Jamie Chan

Jamie Chan is a tutor and freelance programmer with years of experience and a dedicated passion for sharing the joy of programming with as many people as possible. With seven bestselling programming books on Amazon, Jamie's publications stand out for their ability to break down complex concepts into simple terms. Additionally, each book includes complete projects at the end, enabling hands-on learning and a deep understanding of the concepts presented.
Read more about Jamie Chan

Right arrow

Writing our first MySQL code

 

Now, we are ready to get our feet wet and write some SQL code.

 

Type the following lines into the text editor (for the first line, be sure to add a space after the two hyphens):

 

-- Using SELECT to display messages

SELECT 'Hello World';

SELECT 'MySQL is fun!';

 

You should notice that the word SELECT is in blue and 'Hello World' and 'MySQL is fun!' are in brown. (The colors may differ depending on your settings or the MySQL Workbench version that you are using).

 

This is the software’s way of making our code easier to read. Different words serve different purposes in our program, hence they are displayed using different colors. We’ll go into more detail in later chapters.

 

There are two ways to run the SQL commands that we wrote.

 

The first task is to select all the code that we want to run and click on the "Execute Selected" button (the button with a lightning bolt icon).

 

This button should normally be located to the right of the "Save" button (refer to the previous screenshot); it executes the selected portion of the script, or everything if there is no selection.

 

You will see a new panel called "Result Grid," with two tabs as shown below:

 

Image

 

These two tabs give the results of the last two lines of code that we wrote (i.e. the two lines that start with the word SELECT).

 

The first line of code that we wrote does not give any result as it is a comment. We’ll talk about comments in the next section.

 

Besides running all the code at one go, you can also choose to execute them one by one. To do that, simply position your cursor on the line that you want to execute and click on the “Execute Statement” button to run that statement. The “Execute Statement” button shows a lightning bolt and a cursor and is located to the right of the “Execute Selected” button.

 

For instance, if you place your cursor as shown in the image below

 

Image

 

and click on the “Execute Statement” button, you’ll get a single tab in the “Result Grid” that displays the message Hello World.

 

Previous PageNext Page
You have been reading a chapter from
Learn SQL using MySQL in One Day and Learn It Well
Published in: Apr 2024Publisher: PacktISBN-13: 9781836205678
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Jamie Chan

Jamie Chan is a tutor and freelance programmer with years of experience and a dedicated passion for sharing the joy of programming with as many people as possible. With seven bestselling programming books on Amazon, Jamie's publications stand out for their ability to break down complex concepts into simple terms. Additionally, each book includes complete projects at the end, enabling hands-on learning and a deep understanding of the concepts presented.
Read more about Jamie Chan