Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to concatenate strings with sqlkata? #399

Closed
jeansusgodney opened this issue Jul 9, 2020 · 2 comments
Closed

How to concatenate strings with sqlkata? #399

jeansusgodney opened this issue Jul 9, 2020 · 2 comments

Comments

@jeansusgodney
Copy link

I am trying to write this kind of query
SELECT * FROM tbl WHERE id || id2 IN (SELECT column1 || column2 FROM tbl2 WHERE tbl = 'tbl1')

Query query = new Query("tbl2")
                    .Select("column1 || column2 ")
                    .Where("tbl", "tbl1");

return new Query("tbl").WhereIn("id || id2", query):

But they don't return any result

@ahmad-moussawi
Copy link
Contributor

Using SelectRaw can help in this case,
Something like this Example on Playground

var inner = new Query("tbl").SelectRaw("id || id2 as concat_id");

var query = new Query().From(inner, "inner").WhereIn(
    "concat_id", 
    new Query("tbl2")
    .SelectRaw("column1 || column2 as col")
    .Where("tbl", "tbl1")
)

will produce

SELECT
  *
FROM
  (
    SELECT
      id || id2 as concat_id
    FROM
      "tbl"
  ) "inner"
WHERE
  "concat_id" IN (
    SELECT
      column1 || column2 as col
    FROM
      "tbl2"
    WHERE
      "tbl" = 'tbl1'
  )

@ahmad-moussawi
Copy link
Contributor

@jeansusgodney I will close this for now, if you have any feedback feel free to reopen it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants