{"id":3904,"date":"2025-06-06T20:00:50","date_gmt":"2025-06-06T20:00:50","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3904"},"modified":"2026-09-26T13:13:51","modified_gmt":"2026-09-26T07:43:51","slug":"sql-select","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/sql-select\/","title":{"rendered":"SQL SELECT"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>SELECT<\/code> statement is how we <strong>read data<\/strong> from a table. Let\u2019s quickly go through the different ways to use it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Basic Usage<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Select all columns\nSELECT * FROM employees;\n\n-- Select specific columns\nSELECT name, salary FROM employees;\n\n-- Filter rows using WHERE\nSELECT name FROM employees WHERE department = 'HR';\n\n-- Use comparison and logical operators\nSELECT * FROM employees WHERE salary &gt; 50000 AND department = 'IT';\n\n-- Sort results by column\nSELECT name, salary FROM employees ORDER BY salary DESC;\n\n-- Get unique values (no duplicates)\nSELECT DISTINCT department FROM employees;\n\n-- Limit number of rows (varies by DBMS)\n-- MySQL \/ PostgreSQL\nSELECT * FROM employees LIMIT 5;\n-- SQL Server\nSELECT TOP 5 * FROM employees;\n-- Oracle 12c+\nSELECT * FROM employees FETCH FIRST 5 ROWS ONLY;\n\n-- Rename columns in output\nSELECT name AS employee_name, salary AS monthly_salary FROM employees;\n\n-- Use expressions in SELECT\nSELECT name, salary * 12 AS annual_salary FROM employees;\n\n-- SELECT from multiple tables using JOIN (basic preview)\nSELECT e.name, d.name AS department_name\nFROM employees e\nJOIN departments d ON e.department_id = d.id;\n\n-- Create a new table from a SELECT\n-- SQL Server \/ PostgreSQL \/ Oracle\nSELECT * INTO temp_employees FROM employees WHERE department = 'Sales';\n-- MySQL alternative\nCREATE TABLE temp_employees AS\nSELECT * FROM employees WHERE department = 'Sales';<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SELECT<\/code> reads data<\/li>\n\n\n\n<li>Use <code>WHERE<\/code> to filter, <code>ORDER BY<\/code> to sort<\/li>\n\n\n\n<li><code>DISTINCT<\/code> removes duplicates<\/li>\n\n\n\n<li>Use aliases with <code>AS<\/code><\/li>\n\n\n\n<li>Add <code>LIMIT<\/code>, <code>TOP<\/code>, or <code>FETCH<\/code> to limit rows<\/li>\n\n\n\n<li>You can even create new tables using <code>SELECT INTO<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 That\u2019s it! Simple and powerful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SELECT statement is how we read data from a table. Let\u2019s quickly go through the different ways to use it. \ud83d\udd39 Basic Usage \ud83e\udde0 Quick Recap \u2705 That\u2019s it! Simple and powerful.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[1225,979],"tags":[],"class_list":["post-3904","post","type-post","status-publish","format-standard","hentry","category-database","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=3904"}],"version-history":[{"count":3,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3904\/revisions"}],"predecessor-version":[{"id":4025,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3904\/revisions\/4025"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=3904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}