{"id":7928,"date":"2019-04-04T13:10:11","date_gmt":"2019-04-04T13:10:11","guid":{"rendered":"https:\/\/ittutorial.org\/?p=7928"},"modified":"2019-07-18T14:42:53","modified_gmt":"2019-07-18T14:42:53","slug":"oracle-sql-tutorials-chapter-2-3","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/oracle-sql-tutorials-chapter-2-3\/","title":{"rendered":"Oracle SQL Tutorials \u2013 Chapter 2 (Part 3 of 3)"},"content":{"rendered":"<p><strong>OPERATOR PRECEDENCE<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"301\" height=\"210\" class=\"wp-image-7942\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-284.png\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-284.png 301w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-284-300x209.png 300w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-284-130x90.png 130w\" sizes=\"auto, (max-width: 301px) 100vw, 301px\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Let\u2019s list the employees which JOB_ID is SA_REP or AD_PRES , and have salary more than 15000.<\/li>\n<\/ul>\n<pre>SELECT first_name,last_name, job_id, salary \r\nFROM hr.employees \r\nWHERE job_id = 'SA_REP\u2018 OR job_id = 'AD_PRES\u2018 AND salary &gt; 15000;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"268\" height=\"151\" class=\"wp-image-7943\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-285.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>This way, all employess which JOB_ID is SA_REP listed as result. We need to add parenthesis to correct this querry ;<\/p>\n<pre>SELECT first_name,last_name, job_id, salary \r\nFROM hr.employees \r\nWHERE (job_id = 'SA_REP\u2018 OR job_id = 'AD_PRES\u2018) AND salary &gt; 15000;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"291\" height=\"113\" class=\"wp-image-7944\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-286.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>ORDER BY OPERATOR<\/strong><\/p>\n<ul>\n<li>The ORDER BY operator is used to put in order the data that returned from querry.<\/li>\n<li><strong>ASC : <\/strong>Sorts the data in ascending direction.<\/li>\n<li><strong>DESC : <\/strong>Sorts the data in descending direction.<\/li>\n<li>The default sorting is ASC. If you don\u2019t write any or them, the data will be sorted in ascending direction.<\/li>\n<li>Let\u2019s list the employees by the hir_date in ascending direction, older to newer.<\/li>\n<\/ul>\n<pre>SELECT first_name,last_name, job_id, department_id, hire_date \"Hire Date\u201c \r\nFROM hr.employees \r\nORDER BY hire_date ASC ;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"419\" height=\"151\" class=\"wp-image-7945\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-287.png\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-287.png 419w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-287-300x108.png 300w\" sizes=\"auto, (max-width: 419px) 100vw, 419px\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Let\u2019s find the yearly salary of employees and list them by the salary in descending direction.<\/li>\n<\/ul>\n<pre>SELECT employee_id, first_name,last_name, salary*12 \"Yearly Salary\u201c\r\nFROM hr.employees\r\nORDER BY 4 desc ;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"337\" height=\"147\" class=\"wp-image-7946\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-288.png\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-288.png 337w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-288-300x131.png 300w\" sizes=\"auto, (max-width: 337px) 100vw, 337px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>ASSIGNING VARIABLE<\/strong><\/p>\n<ul>\n<li>Let\u2019s list the employees which Department ID is 90, using variable.<\/li>\n<\/ul>\n<pre>SELECT employee_id, last_name, salary, department_id\r\nFROM hr.employees\r\nWHERE department_id = &amp;department_num ;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"319\" height=\"92\" class=\"wp-image-7947\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-289.png\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-289.png 319w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-289-300x87.png 300w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"500\" class=\"wp-image-7948\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-290.png\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-290.png 522w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/word-image-290-300x287.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OPERATOR PRECEDENCE &nbsp; Let\u2019s list the employees which JOB_ID is SA_REP or AD_PRES , and have salary more than 15000. SELECT first_name,last_name, job_id, salary FROM hr.employees WHERE job_id = &#8216;SA_REP\u2018 OR job_id = &#8216;AD_PRES\u2018 AND salary &gt; 15000; &nbsp; This way, all employess which JOB_ID is SA_REP listed as result. We need to add parenthesis &hellip;<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1994,3019],"tags":[3212,3009,3048,3010,3198,1340,3001,3013,3215,3216,3202,3014,1572,3206,3208,3207,3209,3205,3003,3210,3211,3204,3017,3016,3199,3200,3214,3213,3201,3000,3012,3203,3002,3008],"class_list":["post-7928","post","type-post","status-publish","format-standard","","category-oracle","category-oracle-sql","tag-desc-syntax","tag-how-to-write-sql","tag-learn-oracle","tag-learn-sql","tag-operator-precedence","tag-oracle-sql","tag-oracle-sql-tutorial","tag-oracle-sql-tutorials","tag-order-by-asc","tag-order-by-desc","tag-order-by-syntax","tag-rules-of-sql","tag-sql","tag-sql-asc","tag-sql-asc-syntax","tag-sql-ascending","tag-sql-ascending-syntax","tag-sql-assigning-variable","tag-sql-commands","tag-sql-desc","tag-sql-desc-syntax","tag-sql-how-to-assign-variable","tag-sql-komutlari","tag-sql-ogren","tag-sql-operator-precedence","tag-sql-order-by","tag-sql-order-by-desc","tag-sql-ordey-by-asc","tag-sql-ordey-by-syntax","tag-sql-tutorial","tag-sql-tutorials","tag-sql-variable","tag-what-is-sql","tag-writing-sql"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/7928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=7928"}],"version-history":[{"count":5,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/7928\/revisions"}],"predecessor-version":[{"id":7950,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/7928\/revisions\/7950"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=7928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=7928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=7928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}