{"id":417,"date":"2024-01-17T13:55:42","date_gmt":"2024-01-17T13:55:42","guid":{"rendered":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/"},"modified":"2024-01-17T13:55:42","modified_gmt":"2024-01-17T13:55:42","slug":"an-introductory-sql-tutorial-how-to-write-simple-queries","status":"publish","type":"post","link":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/","title":{"rendered":"An Introductory SQL Tutorial: How to Write Simple Queries"},"content":{"rendered":"<div class=\"hs-featured-image-wrapper\">\n <a href=\"https:\/\/blog.hubspot.com\/marketing\/sql-tutorial-introduction\" title=\"\" class=\"hs-featured-image-link\"> <img decoding=\"async\" src=\"https:\/\/blog.hubspot.com\/hubfs\/sql-queries.webp\" alt=\"woman uses sql queries\" class=\"hs-featured-image\" style=\"width:auto !important;max-width:50%;float:left;margin:0 15px 15px 0\"> <\/a>\n<\/div>\n<p>Ever heard of SQL? You may have heard about it in the context of data analysis but never thought it would apply to you as a marketer. Or, you may have thought, \u201cThat&#8217;s for the advanced data users. I could never do that.\u201d<\/p>\n<p>Ever heard of SQL? You may have heard about it in the context of data analysis but never thought it would apply to you as a marketer. Or, you may have thought, \u201cThat&#8217;s for the advanced data users. I could never do that.\u201d<\/p>\n<\/p>\n<p>Well, you couldn&#8217;t be more wrong. The most successful marketers are data-driven, and one of the most important parts of being data-driven is collecting data from databases quickly. SQL is the most popular tool out there for doing just that.<\/p>\n<p><a class=\"cta_button\" href=\"https:\/\/www.hubspot.com\/cs\/ci\/?pg=8982b6b5-d870-4c07-9ccd-49a31e661036&amp;pid=53&amp;ecid=&amp;hseid=&amp;hsic=\"><img decoding=\"async\" class=\"hs-cta-img \" style=\"height: auto !important;width: auto !important;max-width: 100% !important;border-width: 0px\" alt=\"Download Now: Introduction to Data Analytics [Free Guide]\" height=\"58\" width=\"530\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/53\/8982b6b5-d870-4c07-9ccd-49a31e661036.png\"><\/a><\/p>\n<p>If your company already stores data in a database, you may need to learn SQL to access the data. But don\u2018t worry \u2014 you\u2019re in the right place to start. Let&#8217;s jump right in.<\/p>\n<h2><strong>How to Query a SQL Database<\/strong><\/h2>\n<ol>\n<li>Ensure you have a database management application (ex. MySQL Workbench, Sequel Pro).<\/li>\n<li>If not, download a database management application and work with your company to connect your database.<\/li>\n<li>Understand your database and its hierarchy.<\/li>\n<li>Find out which fields are in your tables.<\/li>\n<li>Begin writing an SQL query to pull your desired data.<\/li>\n<\/ol>\n<p><em> <\/em><\/p>\n<p>With SQL, you don\u2019t need to download and open a huge Excel spreadsheet to get the answers you seek.<\/p>\n<p>You can ask questions like \u201cWhich customers purchased a red jumpsuit in the past six months?\u201d and SQL fetches the data from your database and returns it to you without you needing to manually sift through a CSV.<\/p>\n<h2><strong>Why use SQL?<\/strong><\/h2>\n<p>SQL is a useful tool for companies that utilize data (hint, most of them do). Here are some examples and reasons why you might want to hop on the SQL train.<\/p>\n<p><em> <\/em><\/p>\n<ul>\n<li>Your data is safer in SQL since it is more difficult for users to accidentally delete it or corrupt it compared to an Excel sheet<\/li>\n<li>SQL allows you to manage datasets exceeding thousands of records<\/li>\n<li>SQL allows multiple users to access the same database seamlessly<\/li>\n<li>Role-based authorizations allow you to control the visibility of sensitive data<\/li>\n<li>SQL facilitates powerful data visualization<\/li>\n<li>SQL enforces data integrity so your data is always accurate and consistent<\/li>\n<\/ul>\n<h2><strong>The SQL Database Hierarchy<\/strong><\/h2>\n<p>An SQL database is a relational database, which means the data is structured in tables that are related to one another based on predefined relationships.<\/p>\n<p>Information in an SQL database is structured hierarchically, similar to a family tree, meaning that items at the top level have a broader scope and branch downward into multiple, more specific sub-entities.<\/p>\n<p>In the context of SQL, the top level is the <strong>database server<\/strong>, also called the <strong>instance<\/strong>. Your instance is where all of your data is stored. Within an instance, there can be multiple <strong>databases<\/strong>, each containing data organized based on some broad categorization.<\/p>\n<p><em> <\/em><\/p>\n<p>A database is broken down into <strong>tables. <\/strong>The table is where the actual data lives. Once you\u2019re at the table level, data is organized by <strong>columns<\/strong> and <strong>rows <\/strong>and housed within <strong>fields<\/strong>, almost exactly like an Excel spreadsheet.<\/p>\n<p><em> <\/em><\/p>\n<p>Let\u2018s pretend we\u2019re working with multiple databases about people in the United States. Entering the query \u201cSHOW DATABASES;\u201d reveals each database in your system, including one titled <em>NewEngland<\/em>.<\/p>\n<p>A database contains tables, and within those tables is your data.<\/p>\n<p>If we use the query \u201cSHOW TABLES in NewEngland;\u201d, the result is tables for each state in New England:<\/p>\n<p><em>people_connecticut, people_maine, people_massachusetts, people_newhampshire, people_rhodeisland, and people_vermont.<\/em><\/p>\n<p>Finally, you need to find out which fields are in the tables. Fields are the specific pieces of data that you can pull from your database.<\/p>\n<p>For example, if you want to pull someone&#8217;s address, the field name may not just be \u201caddress\u201d \u2014 it may be separated into address_city, address_state, address_zip. To figure this out, use the query \u201cDescribe people_massachusetts;\u201d.<\/p>\n<p>This provides a list of all the data you can pull using SQL.<\/p>\n<p>Let&#8217;s do a quick review of the hierarchy using our New England example:<\/p>\n<ul>\n<li>Our database is <em>NewEngland.<\/em><\/li>\n<li>Our tables within that database are <em>people_connecticut, people_maine, people_massachusetts, people_newhampshire, people_rhodeisland, and people_vermont.<\/em><\/li>\n<li>Our fields within the people_massachusetts table include: <em>address_city, address_state, address_zip, hair_color, age, first_name, and last_name.<\/em><\/li>\n<\/ul>\n<p>Now, let\u2019s write some simple SQL queries to pull data from our <em>NewEngland<\/em> database.<\/p>\n<h2><strong>How to Write SQL Queries<\/strong><\/h2>\n<p>Before we begin, ensure you have a database management application allowing you to pull data from your database. Some options include<a href=\"http:\/\/www.mysql.com\/products\/workbench\/\"> MySQL<\/a> or<a href=\"http:\/\/www.sequelpro.com\/\"> Sequel Pro<\/a>.<\/p>\n<p>Start by downloading one of these options, then talk to your company\u2019s IT department about how to connect to your database. Your option will depend on your product&#8217;s back end, so check with your product team to ensure you select the correct one.<\/p>\n<p>To learn how to write an SQL query, let&#8217;s use the following question:<\/p>\n<h4>Who are the people with red hair in Massachusetts who were born in 2003?<\/h4>\n<h4>Using the SELECT command<\/h4>\n<p>SELECT chooses the fields that you want displayed in your chart. This is the specific piece of information that you want to pull from your database. In the example above, we want to find the <em>people<\/em> who fit the rest of the criteria.<\/p>\n<h3>Query 1:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the FROM command<\/h4>\n<p>FROM pinpoints the table that you want to pull the data from.<\/p>\n<p>In the earlier section, we learned that there were six tables for each of the six states in New England: people_connecticut, people_maine, people_massachusetts, people_newhampshire, people_rhodeisland, and people_vermont.<\/p>\n<p>Because we\u2018re looking for people in Massachusetts specifically, we\u2019ll pull data from that specific table.<\/p>\n<p>Here is our SQL query:<\/p>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the WHERE command<\/h4>\n<p>WHERE allows you to filter a query to be more specific. In our example, we want to filter our query to include only people with red hair who were born in 2003. Let&#8217;s start with the red hair filter.<\/p>\n<h3>Query 2:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>hair_color could have been part of your initial SELECT statement if you wanted to look at all of the people in Massachusetts and their hair color. But if you want to filter to see <em>only<\/em> people with red hair, you can do so with a WHERE statement.<\/p>\n<h4>Using the BETWEEN command<\/h4>\n<p>Besides equals (=), BETWEEN is another operator you can use for conditional queries. A BETWEEN statement is true for values that fall between the specified minimum and maximum values.<\/p>\n<p>In our case, we can use BETWEEN to pull records from a specific year, like 2003.<\/p>\n<h3>Query 3:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the AND command<\/h4>\n<p>AND allows you to add additional criteria to your WHERE statement. Remember, we want to filter by people who had red hair in addition to people who were born in 2003. Since our WHERE statement is taken up by the red hair criteria, how can we filter by a specific birth year as well?<\/p>\n<p>That\u2018s where the AND statement comes in. In this case, the AND statement is a date property \u2014 but it doesn\u2019t necessarily have to be. (Note: Check the format of your dates with your product team to ensure they are correct.)<\/p>\n<h3>Query 4:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the OR command<\/h4>\n<p>OR can also be used with a WHERE statement. With AND, both conditions must be true to appear in results (e.g., hair color must be red and must be born in 2003). With OR, either condition must be true to appear in results (e.g., hair color must be red <em>or<\/em> must be born in 2003).<\/p>\n<p>Here\u2019s what an OR statement looks like in action.<\/p>\n<h3>Query 5:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>OR<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the NOT command<\/h4>\n<p>NOT is used in a WHERE statement to display values in which the specified condition is untrue. If we wanted to pull up all Massachusetts residents <em>without<\/em> red hair, we can use the following query.<\/p>\n<h3>Query 6:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE NOT<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the ORDER BY command<\/h4>\n<p>Calculations and organization also can be done within a query. That\u2018s where the ORDER BY and GROUP BY functions come in. First, we\u2019ll look at our SQL queries with the ORDER BY and then GROUP BY functions. Then, we&#8217;ll briefly examine the difference between the two.<\/p>\n<p>An ORDER BY clause allows you to sort by any of the fields that you have specified in the SELECT statement. In this case, let&#8217;s order by last name.<\/p>\n<h3>Query 7:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>ORDER BY<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the GROUP BY command<\/h4>\n<p>GROUP BY is similar to ORDER BY but aggregates similar data. For example, if you have any duplicates in your data, you can use GROUP BY to count the number of duplicates in your fields.<\/p>\n<h3>Query 8:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>GROUP BY<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>ORDER BY VS. GROUP BY<\/h4>\n<p>To show the difference between an ORDER BY statement and a GROUP BY statement, let\u2018s briefly step outside our Massachusetts example to look at a very simple dataset. Below is a list of four employees\u2019 ID numbers and names.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/5eXqYq4ifpyRIU78NQFaw4aL8T9lxXFCm5mJzKJ6YTVfEiwXBwmlLUPmqYM2X1YAxRMrL29auZiwAQLFI8_XAZbx5LWomtHFZSV-qAoEcSom2eGv_YuJamicwj6KVd21J0Mula0xqPLMD7HZMhcSato\" style=\"margin-left: auto;margin-right: auto;width: 450px;height: auto;max-width: 100%\" title=\"\" width=\"450\" height=\"299\"><\/p>\n<p>If we were to use an ORDER BY statement on this list, the names of the employees would get sorted in alphabetical order. The result would look like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/_TmGjULqdiSrS6d0kuHML4rwDbaNbrRnbazatVWhQN49i7EJHwDw_hBqnmKpXxXFAvFwKkOwjvjQfjstx2g3EssXbajn5a-VOEJ72TfpuoMfzyYZEpFB1vhpKqyVVmnfYORDsqynPfcmF-dnQVhu8XU\" style=\"margin-left: auto;margin-right: auto;width: 450px;height: auto;max-width: 100%\" title=\"\" width=\"450\" height=\"291\"><\/p>\n<p>If we used a GROUP BY statement instead, the employees would be counted based on the number of times they appeared in the initial table. Note that Peter appeared twice in the initial table, so the result would look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/IoYeM6XXYntBzV-eA_W1mX_lbU0wOvZ8MFuOAwvwgCAZznneFQ7UkeOC3qM6RwYQGxQyZv7kO1vLAjZxq-omBJ9JR-HevIT6Vo3szQ5HVbpZIRqAxWBUKYhElqs9Yju3FbTbP2gRv7JFD54Gg7dn3yE\" style=\"margin-left: auto;margin-right: auto;width: 450px;height: auto;max-width: 100%\" title=\"\" width=\"450\" height=\"250\"><\/p>\n<p>With me so far? Okay, let\u2018s return to the SQL query we\u2019ve been creating about red-haired Massachusetts people born in 2003.<\/p>\n<h4>Using the LIMIT Function<\/h4>\n<p>It may take a long time to run your queries, depending on the amount of data you have in your database. This can be frustrating, especially if you\u2019ve made an error in your query and now need to wait before continuing. If you want to test a query, the LIMIT function lets you limit the number of results you get.<\/p>\n<p>For example, if we suspect thousands of people have red hair in Massachusetts, we may want to test out our query using LIMIT before we run it in full to ensure we\u2018re getting the information we want. Let\u2019s say, for instance, we only want to see the first 100 people in our result.<\/p>\n<h3>Query 8:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>ORDER BY<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>LIMIT<\/strong><\/p>\n<p><strong> 100<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the INSERT INTO command<\/h4>\n<p>In addition to retrieving information from a relational database, SQL can also be used to modify the contents of a database.<\/p>\n<p>Of course, you\u2019ll need permission to change your company\u2019s data. But, in case you\u2019re ever in charge of managing the contents of a database, we\u2019ll share some queries you should know.<\/p>\n<p>First is the INSERT INTO statement for putting new values into your database.<\/p>\n<p>If we want to add a new person to the Massachusetts table, we can do so by first providing the name of the table we want to modify and the fields within the table we want to add to.<\/p>\n<p>Next, we write VALUE with each respective value we want to add.<\/p>\n<h3>Query 9:<\/h3>\n<p><strong>INSERT INTO<\/strong><\/p>\n<p><strong> people_massachusetts (address_city, address_state, address_zip, hair_color, age, first_name, last_name)<\/strong><\/p>\n<p><strong>VALUES<\/strong><\/p>\n<p><strong> (Cambridge, Massachusetts, 02139, blonde, 32, Jane, Doe)<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>Alternatively, if you are adding a value to every field in the table, you don\u2019t need to specify fields. The values will be added to columns in the order they are listed in the query.<\/p>\n<h3>Query 10:<\/h3>\n<p><strong>INSERT INTO<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>VALUES<\/strong><\/p>\n<p><strong> (Cambridge, Massachusetts, 02139, blonde, 32, Jane, Doe)<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>If you only want to add values to specific fields, you must specify these fields. Say we only want to insert a record with first_name, last_name, and address_state \u2014 we can use the following query.<\/p>\n<h3>Query 11:<\/h3>\n<p><strong>INSERT INTO<\/strong><\/p>\n<p><strong> people_massachusetts (first_name, last_name, address_state)<\/strong><\/p>\n<p><strong>VALUES<\/strong><\/p>\n<p><strong> (Jane, Doe, Massachusetts)<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the UPDATE Command<\/h4>\n<p>You can use UPDATE if you want to replace existing values in your database with different ones. What if, for example, someone is recorded in the database as having red hair when they actually have brown hair? We can update this record with UPDATE and WHERE statements.<\/p>\n<h3>Query 12:<\/h3>\n<p><strong>UPDATE<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>SET<\/strong><\/p>\n<p><strong> hair_color = \u2018brown\u2019<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> first_name = \u2018Jane\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> last_name = \u2018Doe\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>Or, say there\u2019s a problem in your table where some values for \u201caddress_state\u201d appear as \u201cMassachusetts\u201d and others appear as \u201cMA.\u201d To change all instances of \u201cMA\u201d to \u201cMassachusetts,\u201d we can use a simple query and update multiple records simultaneously.<\/p>\n<h3>Query 13:<\/h3>\n<p><strong>UPDATE<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>SET<\/strong><\/p>\n<p><strong> address_state = \u2018Massachusetts\u2019<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> address_state = MA<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>Be careful when using UPDATE. If you don\u2019t specify which records to change with a WHERE statement, you\u2019ll change all values in the table.<\/p>\n<h4>Using the DELETE command<\/h4>\n<p>DELETE removes records from your table. Like with UPDATE, be sure to include a WHERE statement so you don\u2019t accidentally delete your entire table.<\/p>\n<p>Or, if we happen to find several records in our people_massachusetts table who actually lived in Maine, we can delete these entries quickly by targeting the address_state field.<\/p>\n<h3>Query 13:<\/h3>\n<p><strong>DELETE FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> address_state = \u2018maine\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h2>Bonus: Advanced SQL Tips<\/h2>\n<p>Now that you\u2019ve learned how to create a simple SQL query, let&#8217;s discuss some other tricks that you can use to take your queries up a notch, starting with the asterisk.<\/p>\n<h4>* (asterisk)<\/h4>\n<p>When you add an asterisk character to your SQL query, it tells the query that you want to include all the columns of data in your results.<\/p>\n<p>In the Massachusetts example we\u2018ve been using, we\u2019ve only had two column names: first_name and last_name. But let&#8217;s say we had 15 columns of data that we want to see in our results \u2014 it would be a pain to type all 15 column names in the SELECT statement. Instead, if you replace the names of those columns with an asterisk, the query will know to pull all of the columns into the results.<\/p>\n<p>Here&#8217;s what the SQL query would look like.<\/p>\n<h3>Query 13:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> *<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>ORDER BY<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>LIMIT<\/strong><\/p>\n<p><strong> 100<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>% (percent symbol)<\/h4>\n<p>The percent symbol is a wildcard character, meaning it can represent one or more characters in a database value. Wildcard characters are helpful for locating records that share common characters. They are typically used with the LIKE operator to find a pattern in the data.<\/p>\n<p>For instance, if we wanted to get the names of every person in our table whose zip code begins with \u201c02\u201d, we can write the following query.<\/p>\n<h3>Query 14:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> address_zip LIKE \u201802%\u2019<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>Here, \u201c%\u201d stands in for any group of digits that follow \u201c02\u201d, so this query turns up any record with a value for address_zip that begins with \u201c02\u201d.<\/p>\n<h4>LAST 30 DAYS<\/h4>\n<p>Once I started using SQL regularly, I found that one of my go-to queries involved finding which people took an action or fulfilled a certain set of criteria within the last 30 days.<\/p>\n<p>Let&#8217;s pretend today is December 1, 2021. You <em>could <\/em>create these parameters by making the birth_date span between November 1, 2021, and November 30, 2021. That SQL query would look like this:<\/p>\n<h3>Query 15:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182021-11-01\u2019 AND \u20182021-11-30\u2019<\/strong><\/p>\n<p><strong>ORDER BY<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>LIMIT<\/strong><\/p>\n<p><strong> 100<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>But that would require considering which dates cover the last 30 days, and you&#8217;d have to constantly update this query.<\/p>\n<p>Instead, to make the dates automatically span the last 30 days no matter which day it is, you can type this under AND: birth_date &gt;= (DATE_SUB(CURDATE(),INTERVAL 30))<\/p>\n<p>(Note: You&#8217;ll want to double-check this syntax with your product team because it may differ based on the software you use to pull your SQL queries.)<\/p>\n<p>Your full SQL query would, therefore, look as follows.<\/p>\n<h3>Query 16:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date &gt;= (DATE_SUB(CURDATE(),INTERVAL 30))<\/strong><\/p>\n<p><strong>ORDER BY<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>LIMIT<\/strong><\/p>\n<p><strong> 100<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>COUNT<\/h4>\n<p>In some cases, you may want to count the number of times that a criterion of a field appears. For example, let\u2018s say you want to count the number of times the different hair colors appear for the people you are tallying up from Massachusetts.<\/p>\n<p>In this case, COUNT will come in handy, so you don\u2019t have to manually add up the number of people with different hair colors or export that information to Excel.<\/p>\n<p>Here&#8217;s what that SQL query would look like:<\/p>\n<h3>Query 17:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> hair_color,<\/strong><\/p>\n<p><strong> COUNT(hair_color)<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>GROUP BY<\/strong><\/p>\n<p><strong> hair_color<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>AVG<\/h4>\n<p>AVG calculates the average of an attribute in the results of your query, excluding NULL values (empty). In our example, we could use AVG to calculate the average age of Massachusetts residents in our query.<\/p>\n<p>Here\u2019s what our SQL query could look like:<\/p>\n<h3>Query 18:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> AVG(age)<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>SUM<\/h4>\n<p>SUM is another simple calculation you can do in SQL. It calculates the total value of all attributes from your query. So, if we wanted to add up all the ages of Massachusetts residents, we can use the following query.<\/p>\n<h3>Query 19:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> SUM(age)<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using MIN and MAX<\/h4>\n<p>MIN and MAX are two SQL functions that give you the smallest and largest values of a given field. We can use it to identify the oldest and youngest members of our Massachusetts table:<\/p>\n<p>The following query will give us the record of the youngest people.<\/p>\n<h3>Query 20:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> MIN(age)<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>And this query gives us the oldest:<\/p>\n<h3>Query 21:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> MAX(age)<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h4>Using the JOIN command<\/h4>\n<p>There may be a time when you need to access information from two different tables in one SQL query. In SQL, you can use a JOIN clause to do this.<\/p>\n<p>(For those familiar with <a href=\"https:\/\/blog.hubspot.com\/marketing\/how-to-use-excel-tips\">Excel formulas<\/a>, this is similar to using the VLOOKUP formula when you need to combine information from two different sheets in Excel.)<\/p>\n<p>Let\u2018s say we have one table that has data on all Massachusetts residents\u2019 user IDs and birthdates. In addition, we have an entirely separate table containing all Massachusetts residents&#8217; user IDs and their hair color.<\/p>\n<p>If we want to determine the hair color of Massachusetts residents born in 2003, we&#8217;d need to access information from both tables and combine them. This works because both tables share a matching column: user IDs.<\/p>\n<p>Our SELECT statement will also change slightly because we\u2018re calling out fields from two different tables. Instead of just listing out the fields we want to include in our results, we\u2019ll need to specify which table they&#8217;re coming from.<\/p>\n<p>(Note: The asterisk function may be useful here so your query includes both tables in your results.)<\/p>\n<p>To specify a field from a specific table, all we have to do is combine the table\u2018s name with the field\u2019s name. For example, our SELECT statement would say \u201ctable.field\u201d \u2014 with the period separating the table and field names.<\/p>\n<p>We&#8217;re also assuming a few things in this case:<\/p>\n<ol>\n<li>The Massachusetts birthdate table includes the following fields: first_name, last_name, user_id, birthdate<\/li>\n<li>The Massachusetts hair color table includes the following fields: user_id, hair_color<\/li>\n<\/ol>\n<p>Your SQL query would look as follows.<\/p>\n<h3>Query 21:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> birthdate_massachusetts.first_name,<\/strong><\/p>\n<p><strong> birthdate_massachusetts.last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> birthdate_massachusetts JOIN haircolor_massachusetts USING (user_id)<\/strong><\/p>\n<p><strong>WHERE<\/strong><\/p>\n<p><strong> hair_color = \u2018red\u2019<\/strong><\/p>\n<p><strong>AND<\/strong><\/p>\n<p><strong> birth_date BETWEEN \u20182003-01-01\u2019 AND \u20182003-12-31\u2019<\/strong><\/p>\n<p><strong>ORDER BY<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<p>This query would join the two tables using the field \u201cuser_id\u201d which appears in both the birthdate_massachusetts table and the haircolor_massachusetts table. You can then see a table of people born in 2003 with red hair.<\/p>\n<h4>Using a CASE statement<\/h4>\n<p>Use a CASE statement when you want to return different results to your query based on which condition is met. Conditions are evaluated in order. The corresponding result is returned once a condition is met, and all following conditions are skipped over.<\/p>\n<p>You can include an ELSE condition at the end if no conditions are met. Without an ELSE, the query will return NULL if no conditions are met.<\/p>\n<p>Here\u2019s an example of using CASE to return a string based on the query.<\/p>\n<h3>Query 22:<\/h3>\n<p><strong>SELECT<\/strong><\/p>\n<p><strong> first_name,<\/strong><\/p>\n<p><strong> last_name<\/strong><\/p>\n<p><strong>FROM<\/strong><\/p>\n<p><strong> people_massachusetts<\/strong><\/p>\n<p><strong>CASE<\/strong><\/p>\n<p><strong> WHEN hair_color = \u2018brown\u2019 THEN \u2018This person has brown hair.\u2019<\/strong><\/p>\n<p><strong> WHEN hair_color = \u2018blonde\u2019 THEN \u2018This person has blonde hair.\u2019<\/strong><\/p>\n<p><strong> WHEN hair_color = \u2018red\u2019 THEN \u2018This person has red hair.\u2019<\/strong><\/p>\n<p><strong> ELSE \u2018Hair color not known.\u2019<\/strong><\/p>\n<p><strong>END<\/strong><\/p>\n<p><strong>;<\/strong><\/p>\n<h2><strong>Basic SQL Queries Marketers Should Know<\/strong><\/h2>\n<p>Congratulations! You\u2018re ready to run your own SQL queries.<\/p>\n<p>While there\u2019s a lot more you can do with SQL, I hope you found this overview of the basics helpful so you can get your hands dirty.<\/p>\n<p>With a strong foundation of the basics, you can navigate SQL better and work toward some of the more complex examples.<\/p>\n<p><em>Editor&#8217;s note: This post was originally published in March 2015 and has been updated for comprehensiveness.<\/em><\/p>\n<p><a class=\"cta_button\" href=\"https:\/\/www.hubspot.com\/cs\/ci\/?pg=69023555-f25f-4e24-94d7-1f6546fec5d7&amp;pid=53&amp;ecid=&amp;hseid=&amp;hsic=\"><img loading=\"lazy\" decoding=\"async\" class=\"hs-cta-img \" style=\"height: auto !important;width: auto !important;max-width: 100% !important;border-width: 0px\" alt=\"New call-to-action\" height=\"226\" width=\"646\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/53\/69023555-f25f-4e24-94d7-1f6546fec5d7.png\"><\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/track.hubspot.com\/__ptq.gif?a=53&amp;k=14&amp;r=https%3A%2F%2Fblog.hubspot.com%2Fmarketing%2Fsql-tutorial-introduction&amp;bu=https%253A%252F%252Fblog.hubspot.com%252Fmarketing&amp;bvt=rss\" alt=\"\" width=\"1\" height=\"1\" style=\"min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever heard of SQL? You may have heard about it in the context of data analysis but never thought it would apply to you as a marketer. Or, you may have thought, \u201cThat&#8217;s for the advanced data users. I could never do that.\u201d Ever heard of SQL? You may have heard about it in the [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":416,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-417","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An Introductory SQL Tutorial: How to Write Simple Queries - Bell Marketing Solutions<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Introductory SQL Tutorial: How to Write Simple Queries - Bell Marketing Solutions\" \/>\n<meta property=\"og:description\" content=\"Ever heard of SQL? You may have heard about it in the context of data analysis but never thought it would apply to you as a marketer. Or, you may have thought, \u201cThat&#8217;s for the advanced data users. I could never do that.\u201d Ever heard of SQL? You may have heard about it in the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/\" \/>\n<meta property=\"og:site_name\" content=\"Bell Marketing Solutions\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-17T13:55:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.hubspot.com\/hubfs\/sql-queries.webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"An Introductory SQL Tutorial: How to Write Simple Queries\",\"datePublished\":\"2024-01-17T13:55:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/\"},\"wordCount\":3685,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/2059920425.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/\",\"url\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/\",\"name\":\"An Introductory SQL Tutorial: How to Write Simple Queries - Bell Marketing Solutions\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/2059920425.png\",\"datePublished\":\"2024-01-17T13:55:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#primaryimage\",\"url\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/2059920425.png\",\"contentUrl\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/2059920425.png\",\"width\":598,\"height\":398},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/index.php\\\/2024\\\/01\\\/17\\\/an-introductory-sql-tutorial-how-to-write-simple-queries\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"An Introductory SQL Tutorial: How to Write Simple Queries\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/#website\",\"url\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/\",\"name\":\"Bell Marketing Solutions\",\"description\":\"Where Service Matters\",\"publisher\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/#organization\",\"name\":\"Bell Marketing Solutions\",\"url\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/DesignEvo-RedDragonTransparent.png\",\"contentUrl\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/DesignEvo-RedDragonTransparent.png\",\"width\":500,\"height\":500,\"caption\":\"Bell Marketing Solutions\"},\"image\":{\"@id\":\"https:\\\/\\\/bellmarketingsolutions.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An Introductory SQL Tutorial: How to Write Simple Queries - Bell Marketing Solutions","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/","og_locale":"en_US","og_type":"article","og_title":"An Introductory SQL Tutorial: How to Write Simple Queries - Bell Marketing Solutions","og_description":"Ever heard of SQL? You may have heard about it in the context of data analysis but never thought it would apply to you as a marketer. Or, you may have thought, \u201cThat&#8217;s for the advanced data users. I could never do that.\u201d Ever heard of SQL? You may have heard about it in the [&hellip;]","og_url":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/","og_site_name":"Bell Marketing Solutions","article_published_time":"2024-01-17T13:55:42+00:00","og_image":[{"url":"https:\/\/blog.hubspot.com\/hubfs\/sql-queries.webp","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#article","isPartOf":{"@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/"},"author":{"name":"","@id":""},"headline":"An Introductory SQL Tutorial: How to Write Simple Queries","datePublished":"2024-01-17T13:55:42+00:00","mainEntityOfPage":{"@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/"},"wordCount":3685,"commentCount":0,"publisher":{"@id":"https:\/\/bellmarketingsolutions.com\/#organization"},"image":{"@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#primaryimage"},"thumbnailUrl":"https:\/\/bellmarketingsolutions.com\/wp-content\/uploads\/2024\/01\/2059920425.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/","url":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/","name":"An Introductory SQL Tutorial: How to Write Simple Queries - Bell Marketing Solutions","isPartOf":{"@id":"https:\/\/bellmarketingsolutions.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#primaryimage"},"image":{"@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#primaryimage"},"thumbnailUrl":"https:\/\/bellmarketingsolutions.com\/wp-content\/uploads\/2024\/01\/2059920425.png","datePublished":"2024-01-17T13:55:42+00:00","breadcrumb":{"@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#primaryimage","url":"https:\/\/bellmarketingsolutions.com\/wp-content\/uploads\/2024\/01\/2059920425.png","contentUrl":"https:\/\/bellmarketingsolutions.com\/wp-content\/uploads\/2024\/01\/2059920425.png","width":598,"height":398},{"@type":"BreadcrumbList","@id":"https:\/\/bellmarketingsolutions.com\/index.php\/2024\/01\/17\/an-introductory-sql-tutorial-how-to-write-simple-queries\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bellmarketingsolutions.com\/"},{"@type":"ListItem","position":2,"name":"An Introductory SQL Tutorial: How to Write Simple Queries"}]},{"@type":"WebSite","@id":"https:\/\/bellmarketingsolutions.com\/#website","url":"https:\/\/bellmarketingsolutions.com\/","name":"Bell Marketing Solutions","description":"Where Service Matters","publisher":{"@id":"https:\/\/bellmarketingsolutions.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bellmarketingsolutions.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/bellmarketingsolutions.com\/#organization","name":"Bell Marketing Solutions","url":"https:\/\/bellmarketingsolutions.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bellmarketingsolutions.com\/#\/schema\/logo\/image\/","url":"https:\/\/bellmarketingsolutions.com\/wp-content\/uploads\/2022\/09\/DesignEvo-RedDragonTransparent.png","contentUrl":"https:\/\/bellmarketingsolutions.com\/wp-content\/uploads\/2022\/09\/DesignEvo-RedDragonTransparent.png","width":500,"height":500,"caption":"Bell Marketing Solutions"},"image":{"@id":"https:\/\/bellmarketingsolutions.com\/#\/schema\/logo\/image\/"}}]}},"jetpack_featured_media_url":"https:\/\/bellmarketingsolutions.com\/wp-content\/uploads\/2024\/01\/2059920425.png","_links":{"self":[{"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=417"}],"version-history":[{"count":0,"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/417\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/media\/416"}],"wp:attachment":[{"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/categories?post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bellmarketingsolutions.com\/index.php\/wp-json\/wp\/v2\/tags?post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}