{"id":38093127,"url":"https://github.com/henryhamon/sql-builder","last_synced_at":"2026-01-16T20:59:17.934Z","repository":{"id":50088895,"uuid":"247751416","full_name":"henryhamon/sql-builder","owner":"henryhamon","description":"A flexible and powerful SQL query string builder for InterSystems IRIS","archived":false,"fork":false,"pushed_at":"2024-07-17T13:43:16.000Z","size":88,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-17T16:51:37.232Z","etag":null,"topics":["intersystems-iris","sqlbuilder"],"latest_commit_sha":null,"homepage":"","language":"ObjectScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henryhamon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-16T15:45:38.000Z","updated_at":"2024-07-17T13:43:20.000Z","dependencies_parsed_at":"2024-07-17T16:55:44.328Z","dependency_job_id":null,"html_url":"https://github.com/henryhamon/sql-builder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/henryhamon/sql-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhamon%2Fsql-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhamon%2Fsql-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhamon%2Fsql-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhamon%2Fsql-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henryhamon","download_url":"https://codeload.github.com/henryhamon/sql-builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhamon%2Fsql-builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28482456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["intersystems-iris","sqlbuilder"],"created_at":"2026-01-16T20:59:17.067Z","updated_at":"2026-01-16T20:59:17.916Z","avatar_url":"https://github.com/henryhamon.png","language":"ObjectScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gitter](https://img.shields.io/badge/Available%20on-Intersystems%20Open%20Exchange-00b2a9.svg)](https://openexchange.intersystems.com/package/sql-builder)\n\n# SQLBuilder #\n\nA flexible and powerful SQL query string builder for InterSystems IRIS\n\n## Benefits ##\n\t1. Nice and clean object oriented methods instead of having to use concatenation\n  \tand substituition to generate dynamic queries\n\t2. Flexibility to build query adding clauses with logical conditions\n\n## Installation ##\n\n### Docker ###\n\nOpen terminal and clone/git pull the repo into any local directory\n\n```\n$ git clone https://github.com/henryhamon/sql-builder.git\n```\n\nOpen the terminal in this directory and run:\n\n```\n$ docker-compose build\n```\n\nRun the IRIS container with your project:\n```\n$ docker-compose up -d\n```\n\n## How to Run the Application\nOpen InterSystems IRIS terminal:\n\n```\n$ docker-compose exec iris iris session iris\nUSER\u003ezn \"IRISAPP\"\nIRISAPP\u003eWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").GetSQL()\n```\n\n## Examples ##\n\n```cos\nSet tRS = ##class(gen.SQLBuilder).%New(\"sample.person\").Where(\"Age = ?\", 30).Execute()\n```\n\nSQL Executed:\n```sql\nSelect * From sample.person Where Age = '30'\n```\n\n## Documentation ##\n\n#### Execute(Output tSC As %Status = \"\", Args...) as %ResultSet\nExecute the Query returning the ResultSet\n\n#### GetSQL() as %String\nGet the SQL Query string\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person\n```\n\n#### Prepare(tSC As %Status) as %ResultSet\nPrepare the query ResultSet\n\n```\nIRISAPP\u003eSet tRS = ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN, Age\").From(\"sample.person\").Between(\"Age\",10,50).Prepare()\nIRISAPP\u003eWrite $ClassName(tRS)\n%Library.ResultSet\n```\n\n### SELECT\n\n#### Select(params As %String = \"\")\nCreates a Select query\ntaking an optional line string of columns for the query with comma separator\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person\n```\n\ndefaulting to * if none are specified when the query is built\n```\nWrite ##class(gen.SQLBuilder).%New().Select().From(\"sample.person\").GetSQL()\n```\n**Output**\n```sql\nSelect * From sample.person\n```\n\n#### Column(pField, pAlias As %String = \"\")\nAdd Columns on Select query\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").Column(\"age\").From(\"sample.person\").Between(\"Age\",10,50).GetSQL()\n```\n**Output**\n```sql\nSelect name,age From sample.person Where (Age BETWEEN 10 AND 50)\n```\n\ntaking an optional Alias as second parameter\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\",\"nome\").Column(\"age\",\"idade\").From(\"sample.person\").Between(\"Age\",10,50).GetSQL()\n```\n**Output**\n```sql\nSelect name As nome,age As idade From sample.person Where (Age BETWEEN 10 AND 50)\n```\n\n#### From(pTableName As %String)\nFROM\nSpecifies the table used in the current query\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person\n```\n\n#### As(pAlias As %String)\nAdd an Alias for Table\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").As(\"pessoa\").GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person As pessoa\n```\n\n#### %New(pTableName As %String)\nSpecifies the table used in the current query when create a SQLBuilder instance\n```\nWrite ##class(gen.SQLBuilder).%New(\"sample.person\").Select(\"name, ssn\").GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person\n```\n\n#### Limit(pNumberOfRows As %Integer = \"\")\nAdds a TOP clause to the query\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").Limit(10).GetSQL()\n```\n**Output**\n```sql\nSelect TOP 10 name From sample.person\n```\n\n#### Order(pOrderBy As %String)\nORDER BY\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN\").From(\"sample.person\").Order(\"Name\").GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN From sample.person Order By Name\n```\n\n#### OrderBy(pOrderBy As %String)\nORDER BY\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN\").From(\"sample.person\").Order(\"Name\").GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN From sample.person Order By Name\n```\n\n#### Top(pNumberOfRows As %Integer = \"\")\nAdds a TOP clause to the query\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").Top(10).GetSQL()\n```\n**Output**\n```sql\nSelect TOP 10 name From sample.person\n```\n\n#### TopIf(pCondition, pNumberOfRows As %Integer = \"\")\nAdds a TOP clause to the query when a condition is true\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").TopIf(1=1,10).GetSQL()\n```\n**Output**\n```sql\nSelect TOP 10 name From sample.person\n```\n\n```\nWrite ##class(gen.SQLBuilder).%New(\n).Select().Column(\"name\").From(\"sample.person\").TopIf(2=1,10).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person\n```\n\n\n### WHERE Clauses\n\n#### And(args...)\nAdd an AND on Where\n```\nWrite ##class(gen.SQLBuilder).%New(\n).Select(\"name, ssn\").From(\"sample.person\"\n).Where(\"Name %STARSTSWITH ?\",\"Jo\").And(\"Age \u003e ?\", 10).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo' AND Age \u003e '10'\n```\n\n#### AndIf(pCondition, args...)\nAdd an AND on Where clause when a condition is true\nFirst parameter is a boolean condition Second parameter is the instruction with one or multiples?\nnext arguments are the values\n```\nWrite ##class(gen.SQLBuilder).%New(\n).Select(\"name, ssn\").From(\"sample.person\"\n).Where(\"Name %STARSTSWITH ?\",\"Jo\").AndIf(5 \u003e 5, \"Age = ?\", 5).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo'\n```\n```\nWrite ##class(gen.SQLBuilder).%New(\n).Select(\"name, ssn\").From(\"sample.person\"\n).Where(\"Name %STARSTSWITH ?\",\"Jo\").AndIf(10 \u003e 1, \"Age = ?\", 10).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo' AND Age = '10'\n```\n\n#### Between(pProp, pInferior, pSuperior, pType=0)\nAdd an BETWEEN on Where\nfirst parameter is the column name\nsecond and third parameters are the values\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").Between(\"Age\",10,50).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where (Age BETWEEN 10 AND 50)\n```\n\n#### Or(args...)\nAdd an OR on Where clause\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\"\n).From(\"sample.person\"\n).Where(\"Name %STARSTSWITH ?\",\"Jo\").Or(\"Age = ?\", 10).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo' OR Age = '10'\n```\n\n#### OrIf(pCondition, args...)\nAdd an OR on Where clause when a condition is true\nFirst parameter is a boolean condition Second parameter is the instruction with one or multiples?\nnext arguments are the values\n```\nWrite ##class(gen.SQLBuilder).%New(\n).Select(\"name, ssn\").From(\"sample.person\"\n).Where(\"Name %STARSTSWITH ?\",\"Jo\").OrIf(5 \u003e 5, \"Age = ?\", 5).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo'\n```\n\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").Where(\"Name %STARSTSWITH ?\",\"Jo\").OrIf(10 \u003e 1, \"Age = ?\", 10).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo' OR Age = '10'\n```\n\n#### In(pColumn, args...)\nAdds an IN clause to the query\nO primeiro parâmetro é o nome da coluna\nOs demais parâmetros são os valores\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").In(\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person Where age In ('10','20','30','40')\n```\n\n#### InIf(pCondition, pColumn, args...)\nAdds an IN clause to the query when a condition is true\n```\nWrite ##class(gen.SQLBuilder).%New(\n).Select().Column(\"name\").From(\"sample.person\"\n).InIf(5\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person\n```\n\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").InIf(6\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person Where age In ('10','20','30','40')\n```\n\n#### NotIn(pColumn, args...)\nAdds an NOT IN clause to the query\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").NotIn(\"age\",10,20,30,40).GetSQL()\n**Output**\n```sql\nSelect name From sample.person Where age Not In ('10','20','30','40')\n```\n\n#### NotInIf(pCondition, pColumn, args...)\nAdds a NOT IN clause to the query when a condition is true\n\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").NotInIf(5\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person\n```\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").NotInIf(6\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person Where age Not In ('10','20','30','40')\n```\n\n#### Where(args...)\nAdd Where clause\nFirst parameter is the instruction with one or multiples?\nnext arguments are the values\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").Where(\"Name %STARSTSWITH ?\",\"Jo\").GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo'\n```\n\nA complex example:\n```\nWrite ##class(gen.SQLBuilder).%New(\n\t).Select(\"ID, Name, SSN, Age\").From(\"sample.person\"\n\t).Where(\"Age In (?,?,?,?)\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN, Age From sample.person Where Age In ('10','20','30','40')\n```\n\nFor multiples clauses will add an AND\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\"\n\t).From(\"sample.person\").Where(\"Name %STARSTSWITH ?\",\"Jo\"\n\t).Where(\"Age \u003e ?\",10).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Name %STARSTSWITH 'Jo' AND Age \u003e '10'\n```\n\n#### WhereIf(pCondition, args...)\nAdd a Where or an AND on Where clause when a condition is true\nFirst parameter is a boolean condition Second parameter is the instruction with one or multiples?\nnext arguments are the values\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").WhereIf(5 \u003e 5, \"Age = ?\", 5).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person\n```\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"name, ssn\").From(\"sample.person\").WhereIf(10 \u003e 1, \"Age = ?\", 10).GetSQL()\n```\n**Output**\n```sql\nSelect name, ssn From sample.person Where Age = '10'\n```\n\n#### WhereIn(pColumn, args...)\nAdds an IN clause to the query\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").WhereIn(\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person Where age In ('10','20','30','40')\n```\n\n#### WhereInIf(pCondition, pColumn, args...)\nAdds an IN clause to the query when a condition is true\n\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").WhereInIf(5\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person\n```\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").WhereInIf(6\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person Where age In ('10','20','30','40')\n```\n\n#### WhereNotIn(pColumn, args...)\nAdds an NOT IN clause to the query\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").WhereNotIn(\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person Where age Not In ('10','20','30','40')\n```\n\n#### WhereNotInIf(pCondition, pColumn, args...)\nAdds a NOT IN clause to the query when a condition is true\n\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").WhereNotInIf(5\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person\n```\n```\nWrite ##class(gen.SQLBuilder).%New().Select().Column(\"name\").From(\"sample.person\").WhereNotInIf(6\u003e5,\"age\",10,20,30,40).GetSQL()\n```\n**Output**\n```sql\nSelect name From sample.person Where age Not In ('10','20','30','40')\n```\n\n### GROUP\n\n#### GroupBy(pGroupBy As %String)\nGROUP BY\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN\").From(\"sample.person\").GroupBy(\"Name\").GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN From sample.person Group By Name\n```\n\nGrouping on multiple fields is supported\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN\").From(\"sample.person\").GroupBy(\"Name\").GroupBy(\"Age\").GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN From sample.person Group By Name,Age\n```\n\n#### Having(args...)\nAdd HAVING on GROUP BY clause\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN\").From(\"sample.person\").GroupBy(\"Name\").Having(\"Age \u003e ?\", 50).GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN From sample.person Group By Name Having Age \u003e '50'\n```\n\n### JOIN Methods\n\n#### Join(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo add INNER JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New(\n\t).From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).Join(\"sample.Contact As C\",\"P.ID\",\"C.Person\"\n\t).GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone\nFrom sample.person As P Inner Join sample.Contact As C On P.ID = C.Person\n```\n\n#### InnerJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo add INNER JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New(\n\t).From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).JoinRaw(\"sample.Contact As C\",\"P.ID = C.Person AND P.Name = C.Name\"\n\t).GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Inner Join sample.Contact As C On P.ID = C.Person\n```\n\n#### InnerJoinRaw(pTable, pRawClause As %String = \"\")\nTo add INNER JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\").JoinRaw(\"sample.Contact As C\",\"P.ID = C.Person AND P.Name = C.Name\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Inner Join sample.Contact As C On P.ID = C.Person\n```\n\n#### LeftJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo do a LEFT JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\").LeftJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Left Join sample.Contact As C On P.ID = C.Person\n```\n\n#### LeftJoinRaw(pTable, pRawClause As %String)\nTo do a LEFT JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\").LeftJoinRaw(\"sample.Contact As C\",\"P.ID = C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Left Join sample.Contact As C On P.ID = C.Person\n```\n\n#### LeftOuterJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo do a LEFT OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\").LeftOuterJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Left Outer Join sample.Contact As C On P.ID = C.Person\n```\n\n#### LeftOuterJoinRaw(pTable, pRawClause As %String)\nTo do a LEFT OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\").LeftOuterJoinRaw(\"sample.Contact As C\",\"P.ID = C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Left Join sample.Contact As C On P.ID = C.Person\n```\n\n#### CrossJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo do a CROSS JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).CrossJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Cross Join sample.Contact As C On P.ID = C.Person\n```\n\n#### CrossJoinRaw(pTable, pRawClause As %String)\nTo do a CROSS JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).CrossJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Cross Join sample.Contact As C On P.ID = C.Person\n```\n\n#### FullOuterJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo do a FULL OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\").Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\").FullOuterJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Full Outer Join sample.Contact As C On P.ID = C.Person\n```\n\n#### FullOuterJoinRaw(pTable, pRawClause As %String)\nTo do a FULL OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\").Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\").FullOuterJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Full Outer Join sample.Contact As C On P.ID = C.Person\n```\n\n#### OuterJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo do an OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).OuterJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Outer Join sample.Contact As C On P.ID = C.Person\n```\n\n#### OuterJoinRaw(pTable, pRawClause As %String)\nTo do an OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).OuterJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Outer Join sample.Contact As C On P.ID = C.Person\n```\n\n#### RightJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo do a RIGHT JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).RightJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Right Join sample.Contact As C On P.ID = C.Person\n```\n\n#### RightJoinRaw(pTable, pRawClause As %String)\nTo do a RIGHT JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).RightJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone From sample.person As P Right Join sample.Contact As C On P.ID = C.Person\n```\n\n#### RightOuterJoin(pTable, pFirst As %String = \"\", pSecond As %String = \"\", pRawClause As %String = \"\")\nTo do a RIGHT OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument being the first join column and the second join column\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t).RightOuterJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone\nFrom sample.person As P Right Outer Join sample.Contact As C On P.ID = C.Person\n```\n\n#### RightOuterJoinRaw(pTable, pRawClause As %String)\nTo do a RIGHT OUTER JOIN between tables\nThe first argument being the table name with Alias, the next argument the JOIN-ing condition\n\n```\nWrite ##class(gen.SQLBuilder).%New().From(\"sample.person\").As(\"P\"\n\t\t).Select(\"P.ID, P.Name, P.SSN, C.Email, C.Phone\"\n\t\t).RightOuterJoin(\"sample.Contact As C\",\"P.ID\",\"C.Person\").GetSQL()\n```\n**Output**\n```sql\nSelect P.ID, P.Name, P.SSN, C.Email, C.Phone\nFrom sample.person As P Right Outer Join sample.Contact As C On P.ID = C.Person\n```\n\n### UNION\n\n#### Union(pSQL)\nCreates a UNION Query\nThe parameter is another SQLBuilder object\n```\nWrite ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN\").From(\"sample.person\"\n\t).Union( ##class(gen.SQLBuilder).%New().Select(\"ID, Name, SSN\").From(\"sample.person\")\n).GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN From sample.person Union Select ID, Name, SSN From sample.person\n```\n\n#### UnionAll(pSQL)\nCreates a UNION ALL Query\nThe parameter is another SQLBuilder object\n```\nWrite ##class(gen.SQLBuilder).%New(\n\t).Select(\"ID, Name, SSN\").From(\"sample.person\"\n\t).UnionAll( ##class(gen.SQLBuilder).%New(\n\t).Select(\"ID, Name, SSN\").From(\"sample.person\")\n).GetSQL()\n```\n**Output**\n```sql\nSelect ID, Name, SSN From sample.person\nUnion All\nSelect ID, Name, SSN From sample.person\n```\n\n\n## Authors ##\n\n * Leonardo \"Metz\" Metzger [github](https://github.com/leometzger)\n * Henry \"HammZ\" Hamon [github](https://github.com/henryhamon)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryhamon%2Fsql-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenryhamon%2Fsql-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryhamon%2Fsql-builder/lists"}