{"id":75775,"date":"2020-08-20T06:08:30","date_gmt":"2020-08-20T06:08:30","guid":{"rendered":"https:\/\/www.whizlabs.com\/blog\/?p=75775"},"modified":"2020-08-31T11:46:54","modified_gmt":"2020-08-31T11:46:54","slug":"sql-queries-for-beginners","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/","title":{"rendered":"30 Most Common SQL Queries for Beginners"},"content":{"rendered":"<p style=\"text-align: justify;\"><em>Aspiring to learn SQL and build a successful career in data? Here we bring the most common SQL queries for beginners that will help you become a data pro.<\/em><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: justify;\">Computers are machines, and we need a specialized language for communicating with them. Therefore, computer programming languages come with a wide range of instructions to address certain tasks. Programming languages such as SQL, Python, and Java help computers and systems process large and complex data efficiently.<\/span><\/p>\n<p style=\"text-align: justify;\">SQL or Structured Query Language is undoubtedly one of the prominently popular programming languages, especially for its functionalities in access and modification of data in databases. The basic use of SQL for interfacing with databases is the most prominent reason for its popularity.<\/p>\n<blockquote><p>Check Now: <a href=\"https:\/\/www.whizlabs.com\/sql-basics\/\" target=\"_blank\" rel=\"noopener noreferrer\">SQL BASICS TRAINING COURSE<\/a><\/p><\/blockquote>\n<p style=\"text-align: justify;\">Therefore, the demand for learning about SQL has increased recently. One of the most fundamental aspects of learning about SQL is the query. Basically, a query in SQL is a request or question for data. SQL queries for beginners can help in familiarizing themselves with the SQL language.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ea7e02;color:#ea7e02\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ea7e02;color:#ea7e02\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#Top_30_SQL_Queries_for_Beginners\" >Top 30 SQL Queries for Beginners<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#1_Displaying_the_Data_from_All_Columns_in_a_Table\" >1. Displaying the Data from All Columns in a Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#2_Creating_Databases_Tables\" >2. Creating Databases &amp; Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#3_Filtering_out_Data\" >3. Filtering out Data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#4_Obtaining_Data_from_Specific_Columns\" >4. Obtaining Data from Specific Columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#5_Filtering_Data_on_the_Basis_of_Conditions_Joined_with_OR_Operator\" >5. Filtering Data on the Basis of Conditions Joined with OR Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#6_Filtering_Out_Data_by_Joining_Conditions_with_AND_Operator\" >6. Filtering Out Data by Joining Conditions with AND Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#7_Obtain_Non-repeated_Records\" >7. Obtain Non-repeated Records<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#8_Sorting_Data_on_the_Basis_of_Multiple_Columns\" >8. Sorting Data on the Basis of Multiple Columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#9_Obtaining_Data_in_a_Specific_Column_without_NULL\" >9. Obtaining Data in a Specific Column without NULL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#10_Sorting_Data_on_the_basis_of_One_Column\" >10. Sorting Data on the basis of One Column<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#11_Joining_Values_from_Text_Columns_in_One_String\" >11. Joining Values from Text Columns in One String<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#12_Identify_Values_Aligning_with_Specific_Pattern\" >12. Identify Values Aligning with Specific Pattern<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#13_Mathematical_Operators\" >13. Mathematical Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#14_Using_Aliases_of_Tables_and_Columns\" >14. Using Aliases of Tables and Columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#15_Determining_Average_of_Values_in_a_Column\" >15. Determining Average of Values in a Column<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#16_Counting_Number_of_Rows\" >16. Counting Number of Rows<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#17_Determine_Sum_of_Values_in_Columns\" >17. Determine Sum of Values in Columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#18_Find_Intersection_of_Data_Sets\" >18. Find Intersection of Data Sets<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#19_Addition_of_Data_from_Various_Tables\" >19. Addition of Data from Various Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#20_Identifying_Maximum_Value_in_a_Column\" >20. Identifying Maximum Value in a Column<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#21_Identifying_Minimum_Value_in_a_Column\" >21. Identifying Minimum Value in a Column<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#22_Removal_of_Data_from_Tables\" >22. Removal of Data from Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#23_Inserting_Data_into_Table\" >23. Inserting Data into Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#24_Updating_Columns\" >24. Updating Columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#25_Updating_Column_on_the_basis_of_Record_Filtering\" >25. Updating Column on the basis of Record Filtering<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#26_Deleting_Tables\" >26. Deleting Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#27_Database_backup\" >27. Database backup<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#28_Renaming_Tables\" >28. Renaming Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#29_Changing_String_Case\" >29. Changing String Case<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/www.whizlabs.com\/blog\/sql-queries-for-beginners\/#30_Verifying_that_Values_are_Numeric\" >30. Verifying that Values are Numeric<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Top_30_SQL_Queries_for_Beginners\"><\/span>Top 30 SQL Queries for Beginners<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">It is important to consider SQL queries as more than just SQL basics. SQL queries are your tools to use SQL for different tasks without having to go through complicated procedures. So, let us dive into the most frequently asked SQL queries in professional interviews for database-related job roles.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Displaying_the_Data_from_All_Columns_in_a_Table\"><\/span>1. Displaying the Data from All Columns in a Table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">One of the first SQL queries for beginners addresses the function of retrieving data from a table. The query has only one character followed by SELECT, i.e., *, pointing out to all columns in the table. As a result, there is no need for listing the names of all the columns. The additional component and most important one in this query are \u2018FROM,\u2019 followed by the name of the table in question for data retrieval. For example, if you want to obtain data from a table \u2018stars,\u2019 then the query would be,<\/p>\n<pre style=\"text-align: justify;\">SELECT *\r\n\r\nFROM stars;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"2_Creating_Databases_Tables\"><\/span>2. Creating Databases &amp; Tables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">This is also one of the most important SQL queries for beginners, and it is essential to begin working with SQL. The \u201cCREATE\u201d keyword can help you create tables as well as databases as tables within databases. Here is an example of an SQL query for creating a database, entering into it, and then create a table.<\/p>\n<pre style=\"text-align: justify;\">CREATE db_name;\r\n\r\n\/* Use the specified database for executing further queries *\/\r\n\r\nUSE db_name;\r\n\r\nCREATE TABLE authors (author_name VARCHAR(60), author_email VARCHAR(70), author_pay int);<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"3_Filtering_out_Data\"><\/span>3. Filtering out Data<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The \u2018WHERE\u2019 clause is one of the significant SQL queries for beginners for understanding the functionalities of SQL. It helps in filtering data on the basis of certain conditions. For example, in the case of \u2018students\u2019 databases, you can implement a condition such as age&gt;=10. This example would aim to find out records that have a value of 10 or more in the \u2018age\u2019 column.<\/p>\n<pre style=\"text-align: justify;\">SELECT id, name, age\r\n\r\nFROM students\r\n\r\nWHERE age&gt;=10;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"4_Obtaining_Data_from_Specific_Columns\"><\/span>4. Obtaining Data from Specific Columns<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">SQL also offers the opportunity for displaying data from specific columns of a table. You can achieve this by listing the columns after \u2018SELECT.\u2019 Take the example of a \u2018students\u2019 database. If you want to retrieve data regarding \u2018id\u2019 and \u2018name,\u2019 then you can use the following example query,<\/p>\n<pre style=\"text-align: justify;\">SELECT id, name\r\n\r\nFROM students;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"5_Filtering_Data_on_the_Basis_of_Conditions_Joined_with_OR_Operator\"><\/span>5. Filtering Data on the Basis of Conditions Joined with OR Operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">This is an advancement over the basic SQL queries for beginners and offers filtering of data on the basis of multiple conditions. If you want to implement two conditions and want one of the conditions to be fulfilled for filtering data, then you can join the conditions by using the \u2018OR\u2019 operator. In the following example query, let us find out records of students with age of 10 years or more and with the first name \u2018John.\u2019<\/p>\n<pre style=\"text-align: justify;\">SELECT id, name, age\r\n\r\nFROM students\r\n\r\nWHERE age &gt;= 10 OR name = \u2018John\u2019;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"6_Filtering_Out_Data_by_Joining_Conditions_with_AND_Operator\"><\/span>6. Filtering Out Data by Joining Conditions with AND Operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can also find such SQL commands for beginners for in-depth data filtering. This SQL query can provide better data filtering with the use of more than one condition. The \u2018AND\u2019 operator does the trick here. So, improvising on the above-mentioned example query, let us find out records of students with the first name \u2018John\u2019 above the age of 10 years.<\/p>\n<pre style=\"text-align: justify;\">SELECT id, name, age\r\n\r\nFROM students\r\n\r\nWHERE age &gt;= 10 AND name = \u2018John\u2019;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"7_Obtain_Non-repeated_Records\"><\/span>7. Obtain Non-repeated Records<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use the \u2018DISTINCT\u2019 keyword after \u2018SELECT\u2019 for obtaining only a specific type of record, thereby avoiding any repeated records. In the following example query, let us obtain records from the columns of \u2018name\u2019 and \u2018color\u2019 from a table of \u2018clothing.\u2019<\/p>\n<pre style=\"text-align: justify;\">SELECT DISTINCT name, color\r\n\r\nFROM clothing;<\/pre>\n<p style=\"text-align: justify;\">This query would help in verifying whether the values in these columns are the same for multiple records. In case of the same values in more than one record, the query will return only one of the records. Therefore, you can notice that SQL queries for beginners can simplify tasks in interacting with databases.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"8_Sorting_Data_on_the_Basis_of_Multiple_Columns\"><\/span>8. Sorting Data on the Basis of Multiple Columns<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The SQL functionalities also help in sorting data in accordance to the requirements of multiple columns. Here is an example of sorting records according to the column \u2018name\u2019 in descending order followed by the column \u2018id\u2019 in ascending order. If the query identifies records with the same name, then it can sort all records in ascending order on basis of \u2018id.\u2019<\/p>\n<pre style=\"text-align: justify;\">SELECT id, name\r\n\r\nFROM animal\r\n\r\nORDER BY name DESC, id;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"9_Obtaining_Data_in_a_Specific_Column_without_NULL\"><\/span>9. Obtaining Data in a Specific Column without NULL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">SQL queries for beginners also include functions for retrieving data only from rows without the \u201cNULL\u201d in a specific column. Just use \u2018IS NOT NULL,\u2019 and the job is done. Here is an example,<\/p>\n<pre style=\"text-align: justify;\">SELECT name, color\r\n\r\nFROM clothing\r\n\r\nWHERE color IS NOT NULL;<\/pre>\n<p style=\"text-align: justify;\">This example query showcases that the value in \u2018color\u2019 column could not be \u2018NULL.\u2019 It returns the records with value stored in the \u2018color\u2019 column.<\/p>\n<blockquote><p>Also Check &#8211;<a href=\"https:\/\/www.whizlabs.com\/google-cloud-sql-deep-dive\/\" target=\"_blank\" rel=\"noopener noreferrer\"> Google Cloud SQL Deep Dive Training Course<\/a><\/p><\/blockquote>\n<h3><span class=\"ez-toc-section\" id=\"10_Sorting_Data_on_the_basis_of_One_Column\"><\/span>10. Sorting Data on the basis of One Column<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The example SQL query for this objective would require placing the column name followed by \u2018ORDER BY.\u2019 The default sorting method in this query would be alphabetical. However, you can use \u2018DESC,\u2019 followed by the column name for displaying rows in descending order. The following example helps in sorting data into the \u2018id\u2019 and \u2018name\u2019 columns on the basis of \u2018name\u2019 column.<\/p>\n<pre style=\"text-align: justify;\">SELECT id, name\r\n\r\nFROM animal\r\n\r\nORDER BY name;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"11_Joining_Values_from_Text_Columns_in_One_String\"><\/span>11. Joining Values from Text Columns in One String<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">\u2018CONCAT\u2019 function serves the role of joining strings. The following example query returns strings in the \u2018name\u2019 and \u2018category\u2019 columns, joined as a single column of strings. The single-column has a space between the value in the \u2018name\u2019 column and the \u2018category\u2019 column.<\/p>\n<pre style=\"text-align: justify;\">SELECT CONCAT (name, \u2018,\u2019 category)\r\n\r\nFROM tab;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"12_Identify_Values_Aligning_with_Specific_Pattern\"><\/span>12. Identify Values Aligning with Specific Pattern<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">SQL queries for beginners can help in obtaining data from tables that align with specific pattern by using \u2018LIKE&#8217;. The following example query helps in retrieving records from \u2018name\u2019 and \u2018id\u2019 columns that contain a string containing the character \u2018b\u2019 in the \u2018name\u2019 column.<\/p>\n<pre style=\"text-align: justify;\">SELECT id, name\r\n\r\nFROM animal\r\n\r\nWHERE name LIKE \u2018%b%\u2019;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"13_Mathematical_Operators\"><\/span>13. Mathematical Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">SQL queries for beginners can also include the use of mathematical operators. Mathematical operators such as \u201c+,\u201d \u201c*,\u201d \u201c\/\u201d and \u201c-\u201d help in performing arithmetic operations on data in the table. The following example query subtracts the \u2018discount\u2019 from \u2018price\u2019 of products.<\/p>\n<pre style=\"text-align: justify;\">SELECT price \u2013 discount\r\n\r\nFROM product;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"14_Using_Aliases_of_Tables_and_Columns\"><\/span>14. Using Aliases of Tables and Columns<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Aliases for tables and column names can help in joining tables. The following example joins two tables \u2018city\u2019 and \u2018customer.\u2019<\/p>\n<pre style=\"text-align: justify;\">SELECT c.last_name AS lname, t.name AS city\r\n\r\nFROM customer AS c\r\n\r\nINNER JOIN city AS t\r\n\r\n\u00a0\u00a0ON c.id = t.customer_id;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"15_Determining_Average_of_Values_in_a_Column\"><\/span>15. Determining Average of Values in a Column<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">AVG can help in calculating the average of values in a column. Here is an example query of the same,<\/p>\n<pre style=\"text-align: justify;\">SELECT AVG (price)\r\n\r\nFROM product;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"16_Counting_Number_of_Rows\"><\/span>16. Counting Number of Rows<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">This is also one of the basic SQL queries for beginners using \u2018COUNT.\u2019The following example query returns the number of values from \u2018id\u2019 column stored in the \u2018product\u2019 table,<\/p>\n<pre style=\"text-align: justify;\">SELECT COUNT (id)\r\n\r\nFROM product;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"17_Determine_Sum_of_Values_in_Columns\"><\/span>17. Determine Sum of Values in Columns<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">SUM command can help in calculating values of a column as in the following example query,<\/p>\n<pre style=\"text-align: justify;\">SELECT SUM (price)\r\n\r\nFROM product;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"18_Find_Intersection_of_Data_Sets\"><\/span>18. Find Intersection of Data Sets<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">INTERSECT can help in returning the values of the intersection of two data sets. Here is the example query for retrieving last names listed in both tables.<\/p>\n<pre style=\"text-align: justify;\">SELECT last_name FROM customer\r\n\r\nINTERSECT\r\n\r\nSELECT last_name FROM employee;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"19_Addition_of_Data_from_Various_Tables\"><\/span>19. Addition of Data from Various Tables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">UNION ALL operators can help in joining records from various tables only if the records belong to similar data types. The following example returns all rows with last names from \u2018customer\u2019 table and \u2018employee\u2019 table.<\/p>\n<pre style=\"text-align: justify;\">SELECT last_name FROM customer\r\n\r\nUNION ALL\r\n\r\nSELECT last_name FROM employee;<\/pre>\n<p style=\"text-align: justify;\">You can use UNION rather than UNION ALL for selecting all last names without repeated values.<\/p>\n<blockquote><p>Also Check: <a href=\"https:\/\/www.whizlabs.com\/blog\/nosql-vs-sql\/\" target=\"_blank\" rel=\"noopener noreferrer\">NoSQL vs SQL &#8211; Which One is Better?<\/a><\/p><\/blockquote>\n<h3><span class=\"ez-toc-section\" id=\"20_Identifying_Maximum_Value_in_a_Column\"><\/span>20. Identifying Maximum Value in a Column<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The basic command for beginners in SQL is \u2018MAX\u2019 that helps in finding maximum value in a column. Here is an example of the SQL query for finding maximum price of products.<\/p>\n<pre style=\"text-align: justify;\">SELECT MAX (price)\r\n\r\nFROM product;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"21_Identifying_Minimum_Value_in_a_Column\"><\/span>21. Identifying Minimum Value in a Column<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The \u2018MIN\u2019 command can help in finding minimum value in a column. Here is an example query to find minimum price from products<\/p>\n<pre style=\"text-align: justify;\">SELECT MIN (price)\r\n\r\nFROM product;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"22_Removal_of_Data_from_Tables\"><\/span>22. Removal of Data from Tables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use the following example query to remove all data from a table,<\/p>\n<pre style=\"text-align: justify;\">DELETE FROM table1;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"23_Inserting_Data_into_Table\"><\/span>23. Inserting Data into Table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">New records can be added to a table through the \u2018INSERT INTO\u2019 command. The following example query helps in inserting 15 into \u2018id,\u2019 bottle into \u2018name,\u2019 and kitchen supplies into \u2018category\u2019 of the \u2018product\u2019 table.<\/p>\n<pre style=\"text-align: justify;\">INSERT INTO product(id, name, category)\r\n\r\nVALUES (15, 'bottle', 'kitchen supplies');<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"24_Updating_Columns\"><\/span>24. Updating Columns<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Here is an example query for modifying all values in the \u2018company\u2019 column to \u2018XYZ.\u2019<\/p>\n<pre style=\"text-align: justify;\">UPDATE product SET company = \u2018XYZ\u2019;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"25_Updating_Column_on_the_basis_of_Record_Filtering\"><\/span>25. Updating Column on the basis of Record Filtering<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The following example query helps in specifying records for modification.<\/p>\n<pre style=\"text-align: justify;\">UPDATE product\r\n\r\nSET name = \u2018bottle\u2019\r\n\r\nWHERE id = 15;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"26_Deleting_Tables\"><\/span>26. Deleting Tables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The \u2018DROP TABLE\u2019 command can help in deleting a table. Here is an example query for deleting \u2018table1\u2019,<\/p>\n<pre style=\"text-align: justify;\">DROP TABLE table1;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"27_Database_backup\"><\/span>27. Database backup<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The following SQL query can help in creating a script for database backup whenever required,<\/p>\n<pre style=\"text-align: justify;\">BACKUP DATABASE db_name\r\n\r\nTO DISK = \"\/home\/databases\/db_name-backup.db\";<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"28_Renaming_Tables\"><\/span>28. Renaming Tables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The following example query can help in renaming a table on the basis of SQL version and privileges,<\/p>\n<pre style=\"text-align: justify;\">sp_RENAME authors authors_renamed;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"29_Changing_String_Case\"><\/span>29. Changing String Case<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">SQL queries can use UPPER() and LOWER() functions for displaying the output of a table in uppercase or lowercase. For example,<\/p>\n<pre style=\"text-align: justify;\">SELECT UPPER(author_name) FROM authors;\r\n\r\nSELECT LOWER(author_name) FROM authors;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"30_Verifying_that_Values_are_Numeric\"><\/span>30. Verifying that Values are Numeric<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">If you want to check that a specific value is numeric, then you can use the ISNUMERIC function. For example,<\/p>\n<pre style=\"text-align: justify;\">SELECT ISNUMERIC (34);<\/pre>\n<blockquote><p>SQL is the old option, well tried and tested by everyone for data analysis while many new options have also come. Check <a href=\"https:\/\/www.whizlabs.com\/blog\/hive-vs-pig-vs-sql\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hive vs Pig vs SQL<\/a> to know which one is best for you.<\/p><\/blockquote>\n<h4 style=\"text-align: justify;\">Conclusion<\/h4>\n<p style=\"text-align: justify;\">The above-mentioned entries are the most common SQL queries for beginners as well as professionals. As a matter of fact, they serve as important additions among SQL tips and tricks for beginners. The queries help in performing simple tasks with tables such as creating tables and databases, updating columns, retrieving data, and deleting tables.<\/p>\n<p style=\"text-align: justify;\">The next important step for learners would be to dive deeper into the world of SQL with the <a href=\"https:\/\/www.whizlabs.com\/sql-basics\/\" target=\"_blank\" rel=\"noopener noreferrer\">SQL Basics training course<\/a> and discover more. In addition, you would have to get your hands dirty if you want to gain expertise in SQL. So the faster you get hands-on experience in using SQL queries, the better it is for your potential career opportunities!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Aspiring to learn SQL and build a successful career in data? Here we bring the most common SQL queries for beginners that will help you become a data pro. Computers are machines, and we need a specialized language for communicating with them. Therefore, computer programming languages come with a wide range of instructions to address certain tasks. Programming languages such as SQL, Python, and Java help computers and systems process large and complex data efficiently. SQL or Structured Query Language is undoubtedly one of the prominently popular programming languages, especially for its functionalities in access and modification of data in [&hellip;]<\/p>\n","protected":false},"author":220,"featured_media":75794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[6],"tags":[3681,3680,3682,3683],"class_list":["post-75775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-big-data","tag-most-frequently-asked-sql-queries","tag-sql-basics","tag-sql-commands-for-beginners","tag-sql-tips-and-tricks-for-beginners"],"uagb_featured_image_src":{"full":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",600,315,false],"thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners-150x150.jpg",150,150,true],"medium":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners-300x158.jpg",300,158,true],"medium_large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",600,315,false],"large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",600,315,false],"1536x1536":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",600,315,false],"2048x2048":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",600,315,false],"profile_24":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",24,13,false],"profile_48":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",48,25,false],"profile_96":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",96,50,false],"profile_150":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",150,79,false],"profile_300":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",300,158,false],"tptn_thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners-250x250.jpg",250,250,true],"web-stories-poster-portrait":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",600,315,false],"web-stories-publisher-logo":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",96,50,false],"web-stories-thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2020\/08\/sql-queries-for-beginners.jpg",150,79,false]},"uagb_author_info":{"display_name":"Aditi Malhotra","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/aditi\/"},"uagb_comment_info":529,"uagb_excerpt":"Aspiring to learn SQL and build a successful career in data? Here we bring the most common SQL queries for beginners that will help you become a data pro. Computers are machines, and we need a specialized language for communicating with them. Therefore, computer programming languages come with a wide range of instructions to address&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/75775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/users\/220"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=75775"}],"version-history":[{"count":4,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/75775\/revisions"}],"predecessor-version":[{"id":75797,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/75775\/revisions\/75797"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media\/75794"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=75775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=75775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=75775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}