Web2py/DAL equivalent of "not in [a table]"

39 views
Skip to first unread message

Vlad

unread,
May 14, 2019, 6:06:49 PM5/14/19
to web2py-users
What would be an equivalent of the following?

SELECT ID, Name 
FROM   Table1 
WHERE  ID NOT IN (SELECT ID FROM Table2)

Val K

unread,
May 14, 2019, 7:16:26 PM5/14/19
to web2py-users
should help:

sql_str = db()._select(db.tbl2.id)  #note underscore before `select`
db
(~db.tbl1.id.belongs(sql_str)).select(db.tbl1.id, db.tbl1.name)  


Eliezer (Vlad) Tseytkin

unread,
May 14, 2019, 10:49:32 PM5/14/19
to web...@googlegroups.com
works like a charm! 
thank you ! 

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/B1zikfQE8GI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/e1e7ba43-70bd-4dc1-8029-21d0959cd023%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Massimo Di Pierro

unread,
May 15, 2019, 1:28:31 AM5/15/19
to web2py-users
Something is wrong. You are searching that the id of one table is not the id of another table. But that is not a reference.

On Tuesday, 14 May 2019 19:49:32 UTC-7, Vlad wrote:
works like a charm! 
thank you ! 

On Tue, May 14, 2019 at 7:16 PM Val K <valq...@gmail.com> wrote:
should help:

sql_str = db()._select(db.tbl2.id)  #note underscore before `select`
db
(~db.tbl1.id.belongs(sql_str)).select(db.tbl1.id, db.tbl1.name)  






On Wednesday, May 15, 2019 at 1:06:49 AM UTC+3, Vlad wrote:
What would be an equivalent of the following?

SELECT ID, Name 
FROM   Table1 
WHERE  ID NOT IN (SELECT ID FROM Table2)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/B1zikfQE8GI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Eliezer (Vlad) Tseytkin

unread,
May 15, 2019, 1:37:39 AM5/15/19
to web...@googlegroups.com
Oh, no problem, I've adjusted it for my case. My problem was that I wasn't aware about subqueries (_select vs. select), so that was the main take away :)

On Wed, May 15, 2019, 1:28 AM Massimo Di Pierro <massimo....@gmail.com> wrote:
Something is wrong. You are searching that the id of one table is not the id of another table. But that is not a reference.

On Tuesday, 14 May 2019 19:49:32 UTC-7, Vlad wrote:
works like a charm! 
thank you ! 

On Tue, May 14, 2019 at 7:16 PM Val K <valq...@gmail.com> wrote:
should help:

sql_str = db()._select(db.tbl2.id)  #note underscore before `select`
db
(~db.tbl1.id.belongs(sql_str)).select(db.tbl1.id, db.tbl1.name)  






On Wednesday, May 15, 2019 at 1:06:49 AM UTC+3, Vlad wrote:
What would be an equivalent of the following?

SELECT ID, Name 
FROM   Table1 
WHERE  ID NOT IN (SELECT ID FROM Table2)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/B1zikfQE8GI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/B1zikfQE8GI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/09fc266e-ebd0-4920-9a9b-bdd68caba1d4%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages