{"id":1276,"date":"2025-04-06T16:49:58","date_gmt":"2025-04-06T16:49:58","guid":{"rendered":"https:\/\/learnlearn.uk\/ibcs\/?page_id=1276"},"modified":"2025-04-06T16:49:58","modified_gmt":"2025-04-06T16:49:58","slug":"select-queries","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/ibcs\/select-queries\/","title":{"rendered":"SELECT Queries"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Intro<\/h2>\n<div class=\"tabcontent\">\n\n<h2>SQL Queries<\/h2>\n<p>A query is a request for data or information from a database table or combination of tables. This query can be thought of as providing a &#8220;view&#8221; of the database, which means it presents a specific slice or interpretation of the database data according to the query&#8217;s conditions and structure.<\/p>\n<p>Queries that view the database contents use the SELECT keyword<\/p>\n\n<\/div><h2 class=\"tabtitle\">SELECT<\/h2>\n<div class=\"tabcontent\">\n\n<h2>SELECT Query<\/h2>\n<p>The simplest form of SELECT query uses the * wildcard operator to retrieve all database columns from the table.<\/p>\n<p>Here&#8217;s a basic SQL SELECT query that retrieves all columns for all customers in the Customers table:<\/p>\n<pre class=\"\">SELECT * FROM Customers;<\/pre>\n<p>If you only want to retrieve data from certain columns then you can specific the column data the you wish to retrieve:<\/p>\n<pre class=\"\">SELECT CustomerName, EmailAddress FROM Customers;<\/pre>\n<div><\/div>\n\n<\/div><h2 class=\"tabtitle\">WHERE<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Filtering using WHERE<\/h2>\n<p>Queries can filter data based on specific criteria, showing only the data that meets these conditions.<\/p>\n<pre class=\"\">SELECT name, department, salary\u00a0\r\nFROM employees\u00a0\r\nWHERE department = 'Marketing'<\/pre>\n<p>This query selects employees in the Marketing department.<\/p>\n\n<\/div><h2 class=\"tabtitle\">ORDER BY<\/h2>\n<div class=\"tabcontent\">\n\n<h2>ORDER BY Clause<\/h2>\n<p>The ORDER BY clause in SQL is used to sort the result set of a query by one or more columns. It can sort the data in ascending order (which is the default) or descending order, based on the specified column(s).<\/p>\n<h4 class=\"\">Example: Employees Table<\/h4>\n<p>If you want to retrieve all employees&#8217; first and last names, sorted by the LastName in ascending order and then by FirstName in descending order, your query would look like this:<\/p>\n<pre class=\"\">SELECT FirstName, LastName\r\nFROM Employees\r\nORDER BY LastName ASC, FirstName DESC;<\/pre>\n\n<\/div><h2 class=\"tabtitle\">LIKE<\/h2>\n<div class=\"tabcontent\">\n\n<h2>LIKE Operator<\/h2>\n<p>The LIKE operator in SQL is used in a WHERE clause to search for a specified pattern in a column. It&#8217;s particularly useful when you want to perform searches on strings, such as finding rows with columns that contain a certain substring, begin with specific characters, or end with specific characters. The % and _ are two wildcards often used with LIKE:<\/p>\n<ul>\n<li>% represents zero, one, or multiple characters.<\/li>\n<li>_ represents a single character.<\/li>\n<\/ul>\n<pre class=\"\">SELECT * FROM Employees\r\nWHERE Name LIKE 'J%';<\/pre>\n<p>This query will retrieve all rows from Employees where the Name starts with &#8216;J&#8217;, regardless of what follows after &#8216;J&#8217;.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>SQL Queries A query is a request for data or information from a database table or combination of tables. This query can be thought of as providing a &#8220;view&#8221; of the database, which means it presents a specific slice or interpretation of the database data according to the query&#8217;s conditions and structure. Queries that view&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/ibcs\/select-queries\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">SELECT Queries<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":100,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SELECT Queries - IB Computer Science<\/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:\/\/learnlearn.uk\/ibcs\/select-queries\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SELECT Queries - IB Computer Science\" \/>\n<meta property=\"og:description\" content=\"SQL Queries A query is a request for data or information from a database table or combination of tables. This query can be thought of as providing a &#8220;view&#8221; of the database, which means it presents a specific slice or interpretation of the database data according to the query&#8217;s conditions and structure. Queries that view&hellip;&nbsp;Read More &raquo;SELECT Queries\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/ibcs\/select-queries\/\" \/>\n<meta property=\"og:site_name\" content=\"IB Computer Science\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/select-queries\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/select-queries\/\",\"name\":\"SELECT Queries - IB Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\"},\"datePublished\":\"2025-04-06T16:49:58+00:00\",\"dateModified\":\"2025-04-06T16:49:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/select-queries\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/ibcs\/select-queries\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/select-queries\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"IB Computer Science\",\"item\":\"https:\/\/learnlearn.uk\/ibcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SELECT Queries\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"name\":\"IB Computer Science\",\"description\":\"- learnlearn..uk\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\",\"name\":\"IB Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"width\":300,\"height\":41,\"caption\":\"IB Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SELECT Queries - IB Computer Science","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:\/\/learnlearn.uk\/ibcs\/select-queries\/","og_locale":"en_GB","og_type":"article","og_title":"SELECT Queries - IB Computer Science","og_description":"SQL Queries A query is a request for data or information from a database table or combination of tables. This query can be thought of as providing a &#8220;view&#8221; of the database, which means it presents a specific slice or interpretation of the database data according to the query&#8217;s conditions and structure. Queries that view&hellip;&nbsp;Read More &raquo;SELECT Queries","og_url":"https:\/\/learnlearn.uk\/ibcs\/select-queries\/","og_site_name":"IB Computer Science","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/ibcs\/select-queries\/","url":"https:\/\/learnlearn.uk\/ibcs\/select-queries\/","name":"SELECT Queries - IB Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#website"},"datePublished":"2025-04-06T16:49:58+00:00","dateModified":"2025-04-06T16:49:58+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/ibcs\/select-queries\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/ibcs\/select-queries\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/ibcs\/select-queries\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"IB Computer Science","item":"https:\/\/learnlearn.uk\/ibcs\/"},{"@type":"ListItem","position":2,"name":"SELECT Queries"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/ibcs\/#website","url":"https:\/\/learnlearn.uk\/ibcs\/","name":"IB Computer Science","description":"- learnlearn..uk","publisher":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/ibcs\/#organization","name":"IB Computer Science","url":"https:\/\/learnlearn.uk\/ibcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","contentUrl":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","width":300,"height":41,"caption":"IB Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/ibcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"SQL Queries A query is a request for data or information from a database table or combination of tables. This query can be thought of as providing a &#8220;view&#8221; of the database, which means it presents a specific slice or interpretation of the database data according to the query&#8217;s conditions and structure. Queries that view&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1276"}],"collection":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/comments?post=1276"}],"version-history":[{"count":1,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1276\/revisions"}],"predecessor-version":[{"id":1277,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1276\/revisions\/1277"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/media?parent=1276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}