{"id":436,"date":"2021-11-11T15:35:08","date_gmt":"2021-11-11T15:35:08","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/?page_id=436"},"modified":"2021-11-16T12:14:00","modified_gmt":"2021-11-16T12:14:00","slug":"aliases","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/higher\/aliases\/","title":{"rendered":"Aliases"},"content":{"rendered":"<h2>Column Headings<\/h2>\n<p>Aliases can be used to change the column headings in the results of SELECT queries.<\/p>\n<p>Aliases containing spaces must be enclosed in square brackets or quotation marks.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT productName AS &#x5B;Product Name], price as Price\r\nFROM Product<\/pre>\n<p>Calculated Values can also be given meaningful column headings:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT productName AS &#x5B;Product Name], price, quantity, \r\n    price*quantity AS &#x5B;Product Cost]\r\nFROM Product, Order\r\nWHERE Product.productID = Order.productID \r\n   AND order# = 123456;<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT MIN(pricePersonNight) AS &quot;Cheapest Price per Night&quot;, \r\n    MAX(pricePersonNight) AS &quot;Dearest Price per Night&quot;\r\nFROM Hotel;<\/pre>\n<h2>Table Names<\/h2>\n<p>Multi-table queries will include the table names several times:<\/p>\n<ul>\n<li>in the FROM clause<\/li>\n<li>in the WHERE clause (linking the tables&#8217; keys)<\/li>\n<li>in other clauses<\/li>\n<\/ul>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT productCategory, MAX(price) \r\nFROM Product, Supplier \r\nWHERE supplier.location = &quot;Greece&quot; \r\n    AND supplier.supplierID = product.supplierD \r\nGROUP BY productCategory \r\nORDER BY MAX(price) ASC;<\/pre>\n<p>A shorter alias can be created in the FROM clause, and then used elsewhere:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT productCategory, MAX(price) \r\nFROM Product p, Supplier s\r\nWHERE s.location = &quot;Greece&quot;\r\n    AND s.supplierID = p.supplierD \r\nGROUP BY productCategory \r\nORDER BY MAX(price) ASC;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Column Headings Aliases can be used to change the column headings in the results of SELECT queries. Aliases containing spaces must be enclosed in square brackets or quotation marks. SELECT productName AS &#x5B;Product Name], price as Price FROM Product Calculated Values can also be given meaningful column headings: SELECT productName AS &#x5B;Product Name], price, quantity, price*quantity AS &#x5B;Product Cost] FROM Product, Order WHERE Product.productID = Order.productID AND order# = 123456;<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/higher\/aliases\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":417,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-436","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/comments?post=436"}],"version-history":[{"count":8,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/436\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/436\/revisions\/492"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/417"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/media?parent=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}