[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-574164-105":3,"detail-sidebar-cat-1-en-105":79,"doc-detail-574164-en":125},{"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":72,"head_meta":74,"extra_data":76,"updated_unix":78},105,"en","sql-cheatsheet-for-data-analytics-data-querying-and-database-constructs","SQL Cheatsheet for Data Analytics - Data querying and database constructs","","Concise SQL reference focused on data analytics use cases, providing practical query patterns and core database constructs. Covers SELECT retrieval, sorting with ORDER BY, aliasing with AS, and indexing concepts that improve read performance while impacting write operations. Includes operators for filtering with BETWEEN AND and IN, and explains table constraints such as PRIMARY KEY, FOREIGN KEY, NOT NULL, CHECK, and DEFAULT with an example CREATE TABLE. Expands to subquery types (scalar, single-row, multi-row, correlated, inline view) and introduces window and ranking functions plus set operations like INTERSECT and UNION.",{"@graph":14,"@context":71},[15,34,54],{"@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/presentations/","Presentations",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/sql-cheatsheet-for-data-analytics-data-querying-and-database-constructs/574164/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":48,"encodingFormat":47,"isAccessibleForFree":49,"interactionStatistic":50},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/sql-cheatsheet-for-data-analytics-data-querying-and-database-constructs/574164.png","ImageObject",442,249,{"name":42,"@type":43},"Melati","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-14",true,{"@type":51,"interactionType":52,"userInteractionCount":26},"InteractionCounter",{"@type":53},"ViewAction",{"@type":55,"mainEntity":56},"FAQPage",[57,63,67],{"name":58,"@type":59,"acceptedAnswer":60},"What are BETWEEN AND and IN used for in SQL queries?","Question",{"text":61,"@type":62},"BETWEEN AND filters rows where a value falls within a specified range, while IN checks whether a value matches any item in a given list.","Answer",{"name":64,"@type":59,"acceptedAnswer":65},"Which key constraints help maintain data integrity in a table?",{"text":66,"@type":62},"PRIMARY KEY enforces unique, non-null identifiers; FOREIGN KEY links to another table; NOT NULL requires a value; CHECK validates conditions; DEFAULT supplies a value when none is provided.",{"name":68,"@type":59,"acceptedAnswer":69},"How do window and ranking functions differ from subqueries in purpose?",{"text":70,"@type":62},"Window functions compute values across related rows within the same result set (often using OVER, PARTITION BY, and ranking/aggregation). Subqueries are nested queries used to produce values or sets that the outer query can use in SELECT, WHERE, FROM, or comparisons.","https://schema.org",{"og:url":32,"og:type":73,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":75,"canonical":32},"index,follow",{"doc_id":77,"site_id":7},574164,1792014844,{"code":4,"msg":80,"data":81},"success",[82,86,91,96,101,106,111,116,121],{"id":83,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":84,"slug":85},11,90,"presentations",{"id":87,"doc_module":22,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},12,"Resumes",80,"resumes",{"id":92,"doc_module":22,"doc_module_name":25,"category_name":93,"show_sort_weight":94,"slug":95},14,"Invoices",70,"invoices",{"id":97,"doc_module":22,"doc_module_name":25,"category_name":98,"show_sort_weight":99,"slug":100},15,"Posters",60,"posters",{"id":102,"doc_module":22,"doc_module_name":25,"category_name":103,"show_sort_weight":104,"slug":105},16,"Social Media",50,"social-media",{"id":107,"doc_module":22,"doc_module_name":25,"category_name":108,"show_sort_weight":109,"slug":110},17,"Forms",40,"forms",{"id":112,"doc_module":22,"doc_module_name":25,"category_name":113,"show_sort_weight":114,"slug":115},18,"Letters",30,"letters",{"id":117,"doc_module":22,"doc_module_name":25,"category_name":118,"show_sort_weight":119,"slug":120},21,"Paper Templates",5,"papers-templates",{"id":122,"doc_module":22,"doc_module_name":25,"category_name":123,"show_sort_weight":4,"slug":124},158,"General","general-158",{"code":4,"msg":80,"data":126},{"doc_id":77,"user_id":127,"nickname":42,"user_avatar":128,"doc_module":22,"category_id":83,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":129,"file_id":130,"file_url":131,"file_type":132,"file_size":133,"view_count":26,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":33,"language":134,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":135,"faqs":136,"seo_title":137,"seo_description":12,"update_tm":138,"read_time":26},962085570644,"https://ap-avatar.wpscdn.com/davatar_994ba38a5ba835b3df7d355c54d3ed8d","SQL Cheatsheet for Data Analytics Cheat Sheet  \n[by](by sourabhsahu12345 via cheatography.com/192985/cs/40126/)[ sourabhsahu12345](by sourabhsahu12345 via cheatography.com/192985/cs/40126/)[ via](by sourabhsahu12345 via cheatography.com/192985/cs/40126/)[ cheatography.com/192985/cs/40126/](by sourabhsahu12345 via cheatography.com/192985/cs/40126/)  \n\n| RDBMS Softwares |  |\n| --- | --- |\n| Oracle | MYSQL |\n| MS SQL Server | MariaDB |\n| Follow @Sourabh Sahu |  |\n| \u003Cbr>QUERYING DATA |  |\n| \u003Cbr>\u003Cbr>Fetch all columns from the products table: SELECT * FROM products;\u003Cbr>Fetch product IDs and names from the inventory table: SELECT product_id , product_name FROM inventory;\u003Cbr>\u003Cbr>Fetch employee names sorted by their salary in descending order: SELECT employee_name FROM employees ORDER BY salary DESC;\u003Cbr>Fetch customer names sorted by their registration date in ascending order (default): SELECT customer_name FROM customers ORDER BY registration_date;\u003Cbr>ALIASING (AS) |  |\n| \u003Cbr>SELECT name AS product_name FROM products;\u003Cbr>INDEXING |  |\n| \u003Cbr>\u003Cbr>Indexing improves data retrieval speed by creating a reference system. It enhances query performance but may slightly impact insert/update operations.\u003Cbr>Clustered Index: Dictates physical data order, often used for primary keys. Non-Cl‐ ustered Index: Creates separate index structures , allowing multiple indexes for specific columns , without affecting data storage order. |  |\n\nBy sourabhsahu12345  \n[cheatography.com/sourabhsahu12345/](cheatography.com/sourabhsahu12345/)  \nBETWEEN AND IN  \nIN checks if a column value matches any value in a list , while BETWEEN checks if a column value falls within a specified range.  \nSELECT * FROM product WHERE category IN ('Electronics' , 'Clothing' , 'Furniture');  \nSELECT * FROM product WHERE price BETWEEN 20 AND 50;  \nCONSTRAINTS  \nConstraints are rules applied to database tables to ensure data accuracy , integrity , and consistency.  \nPRIMARY KEY enforces unique , non-null values in the \"product_id\" column.  \nFOREIGN KEY links the \"manufacturer_id\"column to a related table.  \nNOT NULL ensures the \"product_name\"must have a value.  \nCHECK enforces a condition , like ensuring\"price\" is positive.  \nDEFAULT assigns a default value to a column when no value is provided during insertion.  \nCREATE TABLE product ( product_id INT PRIMARY KEY , product_name VARCHA‐ R(255) NOT NULL , price DECIMAL(10 , 2) CHECK (price > 0) , manufacturer_id INT , FOREIGN KEY (manufacturer_id) REFERENCES manufacturer(manufacture‐ r_id) , discount DECIMAL(5 , 2) DEFAULT 0.00--Default discount set to 0.00 );  \nNot published yet.  \nLast updated 3rd September, 2023. Page 1 of 4.  \nSUBQUERIES  \nScalar Subquery: Returns a single value and can be used within SELECT , WHERE , or FROM clauses.  \nSELECT product_name , (SELECT MAX(price) FROM products) AS max_price FROM products;  \nSingle-Row Subquery: Subquery that returns a single row of results , typically used in comparison operations.  \nSELECT product_name FROM products WHERE price = (SELECT MAX(price) FROM products);  \nMulti-Row Subquery: Subquery that returns multiple rows , often used with IN , ANY , or ALL operators.  \nSELECT product_name FROM products WHERE manufacturer_id IN (SELECT manufacturer_id FROM manufacturers WHERE country = 'USA');  \nCorrelated Subquery: References values from the outer query within the subquery.  \nSELECT product_name FROM products p WHERE price > (SELECT AVG(price) FROM products WHERE manufacturer_id = p. manufacturer_id);  \nInline View Subquery: Creates a temporary table-like structure for complex subqueries within the FROM clause.  \nSELECT AVG(subquery.avg_price) FROM (SELECT manufacturer_id , AVG(price) AS avg_price FROM products GROUP BY manufacturer_id) AS subquery;  \nSponsored by ApolloPad.com Everyone has a novel in them. Finish Yours!  \n[https://apollopad.com](https://apollopad.com)  \nSQL Cheatsheet for Data Analytics Cheat Sheet  \n[by](by sourabhsahu12345 via cheatography.com/192985/cs/40126/)[ sou","cbCaibModo82sNRy","https://ap.wps.com/l/cbCaibModo82sNRy","pdf",62244,"English","# Querying data\n## Selecting columns and sorting with ORDER BY\n## Aliasing (AS)\n## Indexing\n# Filtering operators and constraints\n## BETWEEN AND and IN\n## Constraints and CREATE TABLE\n# Subqueries\n## Scalar, single-row, multi-row\n## Correlated and inline view subqueries\n# Window and ranking functions\n## ROW_NUMBER, DENSE_RANK, SUM OVER\n# Set operations\n## INTERSECT and UNION","[{\"question\":\"What are BETWEEN AND and IN used for in SQL queries?\",\"answer\":\"BETWEEN AND filters rows where a value falls within a specified range, while IN checks whether a value matches any item in a given list.\"},{\"question\":\"Which key constraints help maintain data integrity in a table?\",\"answer\":\"PRIMARY KEY enforces unique, non-null identifiers; FOREIGN KEY links to another table; NOT NULL requires a value; CHECK validates conditions; DEFAULT supplies a value when none is provided.\"},{\"question\":\"How do window and ranking functions differ from subqueries in purpose?\",\"answer\":\"Window functions compute values across related rows within the same result set (often using OVER, PARTITION BY, and ranking/aggregation). Subqueries are nested queries used to produce values or sets that the outer query can use in SELECT, WHERE, FROM, or comparisons.\"}]","SQL Cheatsheet for Data Analytics - Data querying and database constructs | PDF",1791985492]