on-clause

Oracle MERGE: only NOT MATCHED is triggered

烈酒焚心 提交于 2019-12-10 12:26:33
问题 Database: Oracle Table: CREATE TABLE TABLE_FOR_TESTS ( d DATE, t NUMBER(8) ) MERGE: MERGE INTO TABLE_FOR_TESTS USING DUAL ON ((SELECT COUNT(*) FROM TABLE_FOR_TESTS) = 1) WHEN MATCHED THEN UPDATE SET T = T+1 WHEN NOT MATCHED THEN INSERT (D, T) VALUES (sysdate, 1) or ... ON ((SELECT T FROM TABLE_FOR_TESTS) is not null) ... I will refer to the first version of MERGE, but the second one has the same effect. 1) I run that MERGE for the first time result: expected (because there is no element, the

Any possible way to add parameters to ON clause on include left joins on rails?

二次信任 提交于 2019-12-10 12:18:26
问题 I have a huge complex query like this: @objects = Object.joins({ x: :y }).includes( [:s, { x: { y: :z } }, { l: :m },:q, :w, { important_thing: [:h, :v, :c,:l, :b, { :k [:u, :a] }] } ]).where(conditions).order("x.foo, x.bar") Then i want to show all Objects and only Important_things that were created at between two dates. If i put this on there where clause i dont get all Objects , only Objects that has Important_things between informed dates. A solution using raw sql was this: select * from

How do constant values effect the ON clause of Joins?

隐身守侯 提交于 2019-12-10 03:44:02
问题 I've recently discovered that the ON clause of a LEFT JOIN may contain values such as (1 = 1). This is upsetting to me, as it breaks my perception of how joins function. I've encountered a more elaborate version of the following situation: SELECT DISTINCT Person.ID, ... FROM Person LEFT JOIN Manager ON (Manager.ID = Person.ID OR Manager.ID = -1)) WHERE (...) It's perfectly legal. What does "Manager.ID = -1" accomplish, if anything? How can this effect the Join? 回答1: If person table is: id

How do constant values effect the ON clause of Joins?

感情迁移 提交于 2019-12-05 04:46:30
I've recently discovered that the ON clause of a LEFT JOIN may contain values such as (1 = 1). This is upsetting to me, as it breaks my perception of how joins function. I've encountered a more elaborate version of the following situation: SELECT DISTINCT Person.ID, ... FROM Person LEFT JOIN Manager ON (Manager.ID = Person.ID OR Manager.ID = -1)) WHERE (...) It's perfectly legal. What does "Manager.ID = -1" accomplish, if anything? How can this effect the Join? JCasso If person table is: id name 1 Person One 2 Person Two 3 Person Three 4 Person Four 5 Person Five If manager table is id name -1

SQL join: where clause vs. on clause

痴心易碎 提交于 2019-11-25 22:56:48
问题 After reading it, this is not a duplicate of Explicit vs Implicit SQL Joins. The answer may be related (or even the same) but the question is different. What is the difference and what should go in each? If I understand the theory correctly, the query optimizer should be able to use both interchangeably. 回答1: They are not the same thing. Consider these queries: SELECT * FROM Orders LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID WHERE Orders.ID = 12345 and SELECT * FROM Orders LEFT JOIN