[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-573233-105":3,"doc-detail-573233-en":81,"detail-sidebar-cat-1-en-105":97},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":74,"head_meta":76,"extra_data":78,"updated_unix":80},105,"en","sql-basics-cheat-sheet","SQL Basics Cheat Sheet","","SQL (Structured Query Language) is used to communicate with databases, retrieve specific data, and build complex reports. This cheat sheet introduces sample datasets and demonstrates core querying patterns, including selecting columns, sorting with ORDER BY, and using aliases. It covers filtering with comparison and text operators, common operators like BETWEEN, IN, and IS NOT NULL, and joins such as INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, and NATURAL JOIN.",{"@graph":14,"@context":73},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/template/","Template",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/template/general/","General",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/sql-basics-cheat-sheet/573233/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/sql-basics-cheat-sheet/573233.png","ImageObject",442,249,{"name":42,"@type":43},"Quinn Holloway","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-16","2026-10-13",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",5,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69],{"name":60,"@type":61,"acceptedAnswer":62},"What is SQL used for in databases?","Question",{"text":63,"@type":64},"SQL is used to select specific data and build complex reports from databases.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"How do you sort query results by a column?",{"text":68,"@type":64},"Use ORDER BY with ASC (default) or DESC to control ascending or descending order.",{"name":70,"@type":61,"acceptedAnswer":71},"What is the difference between INNER JOIN and LEFT JOIN?",{"text":72,"@type":64},"INNER JOIN returns rows that match in both tables, while LEFT JOIN returns all rows from the left table and fills non-matching right-side values with NULL.","https://schema.org",{"og:url":32,"og:type":75,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":77,"canonical":32},"index,follow",{"doc_id":79,"site_id":7},573233,1792102883,{"code":4,"msg":82,"data":83},"success",{"doc_id":79,"user_id":84,"nickname":42,"user_avatar":85,"doc_module":22,"category_id":86,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":87,"file_id":88,"file_url":89,"file_type":90,"file_size":91,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":22,"language":92,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":93,"faqs":94,"seo_title":95,"seo_description":12,"update_tm":96,"read_time":4},2336474466712,"https://ap-avatar.wpscdn.com/davatar_a8503ba1806abce46bf441b54a3ca4cd",158,"SQL Basics Cheat Sheet   \nSQL, or Structured Query Language, is a language to talk to databases. It allows you to select specific data and to build complex reports. Today, SQL is a universal language of data. It is used in practically all technologies that process data.  \nSAMPLE DATA  \n\n| COUNTRY |  |  |  |  |  |  |  |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| id |  | name |  | population |  | area |  |\n| 1 |  | France |  | 66600000 |  | 640680 |  |\n| 2 |  | Germany |  | 80700000 |  | 357000 |  |\n| . . . |  | . . . |  | . . . |  | . . . |  |\n| CITY |  |  |  |  |  |  |  |\n| id | name |  | country_id |  | population |  | rating |\n| 1 | Paris |  | 1 |  | 2243000 |  | 5 |\n| 2 | Berlin |  | 2 |  | 3460000 |  | 3 |\n| . . . | . . . |  | . . . |  | . . . |  | . . . |\n\nQUERYING SINGLE TABLE  \nFetch all columns from the country table: SELECT *  \nFROM country;  \nFetch id and name columns from the city table: SELECT id , name  \nFROM city;  \nFetch city names sorted by the rating column in the default ASCending order:  \nSELECT name FROM city  \nORDER BY rating [ASC];  \nFetch city names sorted by the rating column in the DESCending order:  \nSELECT name FROM city  \nORDER BY rating DESC;  \nALIASES  \nCOLUMNS  \nSELECT name AS city_name FROM city;  \nTABLES  \nSELECT [co.name](co.name) , [ci.name](ci.name)[ ](ci.name)FROM city AS ci  \nJOIN country AS co  \nON [ci.country_id = co.id](ci.country_id = co.id);  \nFILTERING THE OUTPUT COMPARISON OPERATORS  \nFetch names of cities that have a rating above 3: SELECT name  \nFROM city  \nWHERE rating > 3 ;  \nFetch names of cities that are neither Berlin nor Madrid: SELECT name  \nFROM city  \nWHERE name ! = 'Berlin 'AND name ! = 'Madrid ' ;  \nTEXT OPERATORS  \nFetch names of cities that start with a 'P' or end with an 's': SELECT name  \nFROM city  \nWHERE name LIKE 'P% 'OR name LIKE '%s ' ;  \nFetch names of cities that start with any letter followed by'ublin' (like Dublin in Ireland or Lublin in Poland):  \nSELECT name FROM city  \nWHERE name LIKE '_ublin ' ;  \nOTHER OPERATORS  \nFetch names of cities that have a population between 500K and 5M:  \nSELECT name FROM city  \nWHERE population BETWEEN 500000 AND 5000000;  \nFetch names of cities that don't miss a rating value: SELECT name  \nFROM city  \nWHERE rating IS NOT NULL;  \nFetch names of cities that are in countries with IDs 1, 4, 7, or 8:  \nSELECT name FROM city  \nWHERE country_id IN (1 , 4 , 7 , 8 ) ;  \nQUERYING MULTIPLE TABLES INNER JOIN  \nJOIN (or explicitly INNER JOIN) returns rows that have matching values in both tables.  \nSELECT [city.name](city.name) , [country.name](country.name)[ ](country.name)FROM city  \n[INNER] JOIN country  \nON [city.country_id = country.id](city.country_id = country.id);  \nCITY COUNTRY  \nid name country_id id name  \n\n| 1 | Paris | 1 | 1 | France |\n| --- | --- | --- | --- | --- |\n| 2 | Berlin | 2 | 2 | Germany |\n\n3 Warsaw 4 3 Iceland  \nLEFT JOIN  \nLEFT JOIN returns all rows from the leȦ table with corresponding rows from the right table. If there's no matching row, NULLs are returned as values from the second table.  \nSELECT [city.name](city.name) , [country.name](country.name)  \nFROM city  \nLEFT JOIN country  \nON [city.country_id = country.id](city.country_id = country.id);  \nCITY COUNTRY  \nid name country_id id name  \n\n| 1 | Paris | 1 | 1 | France |\n| --- | --- | --- | --- | --- |\n| 2 | Berlin | 2 | 2 | Germany |\n| 3 | Warsaw | 4 | NULL | NULL |\n\nRIGHT JOIN  \nRIGHT JOIN returns all rows from the right table with corresponding rows from the leȦ table. If there's no matching row, NULLs are returned as values from the leȦ table.  \nSELECT [city.name](city.name) , [country.name](country.name)[ ](country.name)FROM city  \nRIGHT JOIN country  \nON [city.country_id = country.id](city.country_id = country.id);  \nCITY COUNTRY  \nid name country_id id name  \n\n| 1 | Paris | 1 | 1 | France |\n| --- | --- | --- | --- | --- |\n| 2 | Berlin | 2 | 2 | Germany |\n| NULL | NULL | NULL | 3 | Iceland |\n\nFULL JOIN  \nFULL JOIN (or explicitly FULL OUTER JO","cbCaimm4aI8rK4mP","https://ap.wps.com/l/cbCaimm4aI8rK4mP","pdf",96913,"English","# Querying single table\n## Aliases and column/table selection\n## Filtering the output with operators\n## Text operators\n## Other operators like BETWEEN and IN\n# Querying multiple tables with joins\n## INNER JOIN\n## LEFT JOIN\n## RIGHT JOIN\n## FULL JOIN\n## CROSS JOIN\n## NATURAL JOIN\n# Aggregation and grouping\n## GROUP BY and aggregate functions","[{\"question\":\"What is SQL used for in databases?\",\"answer\":\"SQL is used to select specific data and build complex reports from databases.\"},{\"question\":\"How do you sort query results by a column?\",\"answer\":\"Use ORDER BY with ASC (default) or DESC to control ascending or descending order.\"},{\"question\":\"What is the difference between INNER JOIN and LEFT JOIN?\",\"answer\":\"INNER JOIN returns rows that match in both tables, while LEFT JOIN returns all rows from the left table and fills non-matching right-side values with NULL.\"}]","SQL Basics Cheat Sheet | PDF",1791935279,{"code":4,"msg":82,"data":98},[99,104,109,114,119,124,129,134,138],{"id":100,"doc_module":22,"doc_module_name":25,"category_name":101,"show_sort_weight":102,"slug":103},11,"Presentations",90,"presentations",{"id":105,"doc_module":22,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},12,"Resumes",80,"resumes",{"id":110,"doc_module":22,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},14,"Invoices",70,"invoices",{"id":115,"doc_module":22,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},15,"Posters",60,"posters",{"id":120,"doc_module":22,"doc_module_name":25,"category_name":121,"show_sort_weight":122,"slug":123},16,"Social Media",50,"social-media",{"id":125,"doc_module":22,"doc_module_name":25,"category_name":126,"show_sort_weight":127,"slug":128},17,"Forms",40,"forms",{"id":130,"doc_module":22,"doc_module_name":25,"category_name":131,"show_sort_weight":132,"slug":133},18,"Letters",30,"letters",{"id":135,"doc_module":22,"doc_module_name":25,"category_name":136,"show_sort_weight":55,"slug":137},21,"Paper Templates","papers-templates",{"id":86,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":4,"slug":139},"general-158"]