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

WHERE NOT EXISTS and cross-joins #2787

Closed
overlookmotel opened this issue Dec 28, 2014 · 7 comments
Closed

WHERE NOT EXISTS and cross-joins #2787

overlookmotel opened this issue Dec 28, 2014 · 7 comments
Labels

Comments

@overlookmotel
Copy link
Contributor

I've recently come up against a couple of cases where I can't work out how to do something in Sequelize that I quite commonly do in SQL:

WHERE NOT EXISTS

SELECT *
FROM t1
WHERE NOT EXISTS (
    SELECT *
    FROM t2
    WHERE t2.id = t1.id
)

Cross joins

SELECT *
FROM t1
    INNER JOIN t2 ON t2.x = t1.x
    INNER JOIN t3 ON t3.y = t1.y
WHERE t2.z = t3.z

Are these things possible in Sequelize without resorting to using query()?

@mickhansen
Copy link
Contributor

We generally have really lousy support for doing non-include joins.
Your where not exists can be done by a literal where.

Both are things i'd like users to be able to do in Sequelize without resorting to writing raw queries.
An issue with joins is that we expect the query results do be in a specific format for building instances.

@overlookmotel
Copy link
Contributor Author

Your where not exists can be done by a literal where

How do you mean? Sorry if I'm being dense...

By the way, are the docs on sequelize.js now reflecting the v2 API or still referencing v1.7?

I can look into implementing the cross-join. But not now! My first node/sequelize-based app has just gone into production and I have my hands rather full!

@mickhansen
Copy link
Contributor

Something like where: sequelize.literal('NOT SUBQUERY')

Docs on RTD are v2 but not fully updated

@mickhansen
Copy link
Contributor

And cool, what's the app?

@overlookmotel
Copy link
Contributor Author

@mickhansen sequelize.col() doesn't work in this context does it? Using .literal() is a bit too close to coding the whole query in SQL for my liking. I'm running this on both MySQL and SQLite so would like to keep all my queries running through Sequelize to ensure they run everywhere.

@overlookmotel overlookmotel changed the title How do you... WHERE NOT EXISTS and cross-joins Jun 18, 2015
@stale stale bot added the stale label Jun 29, 2017
@stale stale bot closed this as completed Jul 7, 2017
@joebnb
Copy link

joebnb commented Jul 12, 2022

@overlookmotel in 2022 cross join still not have solution,im waiting for your conturbuting

@overlookmotel
Copy link
Contributor Author

Wait away @joebnb! I'm afraid my focus is elsewhere these days. Perhaps give it a go to implement yourself?

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

No branches or pull requests

3 participants