{"id":1666,"date":"2015-07-23T23:09:33","date_gmt":"2015-07-24T04:09:33","guid":{"rendered":"http:\/\/www.dpriver.com\/blog\/?page_id=1666"},"modified":"2015-07-23T23:48:57","modified_gmt":"2015-07-24T04:48:57","slug":"decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators","status":"publish","type":"page","link":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/","title":{"rendered":"Decoding SQL grammar &#8212; Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators"},"content":{"rendered":"<p>In order to decode Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators, you need to know how Select SQL Statement with set operators was organized after parsing by GSP library.<\/p>\n<p>Take this SQL for example:<\/p>\n<pre>\r\nSELECT 1 from dual  -- first part\r\nunion \r\nSELECT 2 from dual  -- second part\r\n<\/pre>\n<p>There are some properties in TSelectSqlStatement help you to judge whether a Select SQL Statement including set operator or not, if yes, how to get two separate query expressions which is type of TSelectSqlStatement too.  <\/p>\n<h4>GSP Java version of TSelectSqlStatement<\/h4>\n<p><strong>public boolean isCombinedQuery()<\/strong>, this function return true if set operator is used, otherwise, return false. If it&#8217;s a Select SQL Statement with set operators, you can&#8217;t get select list, from clause and other clause from this statement directly. You should get two separate query expressions by using getLeftStmt() and getRightStmt() which can be a Select SQL Statement with set operators recursively.<\/p>\n<p><strong>public int getSetOperator()<\/strong>, return type of following set operators.<\/p>\n<p>    public static final int setOperator_none = 0;<br \/>\n    public static final int setOperator_union = 1;<br \/>\n    public static final int setOperator_unionall = 2;<br \/>\n    public static final int setOperator_intersect = 3;<br \/>\n    public static final int setOperator_intersectall = 4;<br \/>\n    public static final int setOperator_minus = 5;<br \/>\n    public static final int setOperator_minusall = 6;<br \/>\n    public static final int setOperator_except = 7;<br \/>\n    public static final int setOperator_exceptall = 8;<\/p>\n<p><strong>public TSelectSqlStatement getLeftStmt()<\/strong>, return first part of two separate query expressions.<\/p>\n<p><strong>public TSelectSqlStatement getRightStmt()<\/strong>, return second part of two separate query expressions.<\/p>\n<h4>GSP .NET version of TSelectSqlStatement<\/h4>\n<p><strong>SelectSetType<\/strong> is type of TSelectSetType. If value is sltNone, then it&#8217;s an ordinary Select SQL Statement, otherwise, it&#8217;s a Select SQL Statement with set operators.<\/p>\n<p><strong>TSelectSetType = (sltNone,sltUnion,sltUnionAll,sltMinus,sltIntersect,sltIntersectAll,sltExcept,sltExceptAll);<br \/>\n<\/strong><\/p>\n<p><strong>LeftStmt<\/strong> is type of TSelectSqlStatement, return the first part of two separate query expressions.<\/p>\n<p><strong>RightStmt<\/strong> is type of TSelectSqlStatement, return the second part of two separate query expressions.<\/p>\n<p>Once you get a Select SQL Statement with no set operator, you can decode Select SQL Statement illustrated as <a href=\"http:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-statement\/\">this document<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In order to decode Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators, you need to know how Select SQL Statement with set operators was organized after parsing by GSP library. Take this SQL for example: SELECT 1 from dual &#8212; first part union SELECT 2 from dual &#8212; second part There are some properties in TSelectSqlStatement help you to judge whether a Select SQL Statement including set operator or not, if yes, how to get two separate query expressions which is type of TSelectSqlStatement too. GSP Java version of TSelectSqlStatement public boolean isCombinedQuery(), this function return true if\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":235,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"gsp_feature_page_tt.php","meta":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Help you to make better use of General SQL Parser<\/title>\n<meta name=\"description\" content=\"Decoding SQL grammar -- Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Help you to make better use of General SQL Parser\" \/>\n<meta property=\"og:description\" content=\"Decoding SQL grammar -- Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and Data Blog\" \/>\n<meta property=\"article:modified_time\" content=\"2015-07-24T04:48:57+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. 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\":\"Organization\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/#organization\",\"name\":\"SQL and Data Blog\",\"url\":\"https:\/\/www.dpriver.com\/blog\/\",\"sameAs\":[],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png\",\"contentUrl\":\"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png\",\"width\":251,\"height\":72,\"caption\":\"SQL and Data Blog\"},\"image\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/#website\",\"url\":\"https:\/\/www.dpriver.com\/blog\/\",\"name\":\"SQL and Data Blog\",\"description\":\"SQL related blog for database professional\",\"publisher\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dpriver.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/\",\"url\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/\",\"name\":\"Help you to make better use of General SQL Parser\",\"isPartOf\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/#website\"},\"datePublished\":\"2015-07-24T04:09:33+00:00\",\"dateModified\":\"2015-07-24T04:48:57+00:00\",\"description\":\"Decoding SQL grammar -- Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.dpriver.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"List of demos illustrate how to use general sql parser\",\"item\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Decoding SQL grammar &#8212; Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators\"}]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Help you to make better use of General SQL Parser","description":"Decoding SQL grammar -- Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators","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:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/","og_locale":"en_US","og_type":"article","og_title":"Help you to make better use of General SQL Parser","og_description":"Decoding SQL grammar -- Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators","og_url":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/","og_site_name":"SQL and Data Blog","article_modified_time":"2015-07-24T04:48:57+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.dpriver.com\/blog\/#organization","name":"SQL and Data Blog","url":"https:\/\/www.dpriver.com\/blog\/","sameAs":[],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png","contentUrl":"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png","width":251,"height":72,"caption":"SQL and Data Blog"},"image":{"@id":"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/www.dpriver.com\/blog\/#website","url":"https:\/\/www.dpriver.com\/blog\/","name":"SQL and Data Blog","description":"SQL related blog for database professional","publisher":{"@id":"https:\/\/www.dpriver.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dpriver.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/","url":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/","name":"Help you to make better use of General SQL Parser","isPartOf":{"@id":"https:\/\/www.dpriver.com\/blog\/#website"},"datePublished":"2015-07-24T04:09:33+00:00","dateModified":"2015-07-24T04:48:57+00:00","description":"Decoding SQL grammar -- Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators","breadcrumb":{"@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/decoding-sql-grammar-select-sql-statement-with-union-intersect-and-except-set-operators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dpriver.com\/blog\/"},{"@type":"ListItem","position":2,"name":"List of demos illustrate how to use general sql parser","item":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/"},{"@type":"ListItem","position":3,"name":"Decoding SQL grammar &#8212; Select SQL Statement with UNION, INTERSECT, and EXCEPT set operators"}]}]}},"_links":{"self":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/1666"}],"collection":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/comments?post=1666"}],"version-history":[{"count":9,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/1666\/revisions"}],"predecessor-version":[{"id":1669,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/1666\/revisions\/1669"}],"up":[{"embeddable":true,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/235"}],"wp:attachment":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/media?parent=1666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}