union

How to union across multiple tables in SQLAlchemy?

夙愿已清 提交于 2019-12-19 08:02:08
问题 I have a few different notification tables, and I would like to perform a union across all of them to show the user all of their notifications. However, the union is not working as it should. Python code def _get_notifications_query(self, unconfirmed_only=True): ''' Return base query to return this users notifications. @param unconfirmed_only @return Query object ''' requests = ( DBSession.query(FriendshipRequestNotification) .outerjoin(UserFriendshipRequestNotification,

Linq to entities : Unions + Distinct

北战南征 提交于 2019-12-19 05:24:01
问题 I don't know how I can do several union with a distinct. When I use .Distinct with an IEqualityComparer an exception in threw : LINQ to Entities does not recognize the method 'System.Linq.IQueryable' My code is var union = query.Union(query1).Union(query2); union = union.Distinct(new EqualityComparerTransaction()); 回答1: LINQ to Entities does not support the overload of Distinct which takes an IEqualityComparer . When you think about it, it really can't, because LINQ to Entities queries will

Selecting across multiple tables with UNION

泄露秘密 提交于 2019-12-19 00:57:23
问题 I reworked my database from one user table to multiple user tables (divided per role): tblStudents , tblTeachers , tblAdmin When logging in, I didn't want to run three queries to check if the user exists somewhere in my DB. So what I did was put together the following query with union select s.id as id, s.email as email, s.password as password, s.role as role from tblStudents s union select a.id as id, a.email as email, a.password as password, a.role as role from tblAdmin a union select t.id

Select distinct values from multiple columns in same table

放肆的年华 提交于 2019-12-18 14:16:45
问题 I am trying to construct a single SQL statement that returns unique, non-null values from multiple columns all located in the same table. SELECT distinct tbl_data.code_1 FROM tbl_data WHERE tbl_data.code_1 is not null UNION SELECT tbl_data.code_2 FROM tbl_data WHERE tbl_data.code_2 is not null; For example, tbl_data is as follows: id code_1 code_2 --- -------- ---------- 1 AB BC 2 BC 3 DE EF 4 BC For the above table, the SQL query should return all unique non-null values from the two columns,

Zend Framework Select Objects And UNION()

蹲街弑〆低调 提交于 2019-12-18 12:38:57
问题 I'm pretty sure this is not possible in Zend Framework (I have searched the Web, the documentation and issue tracker) but I just want to make sure so I'm asking here. $select = $this->select(); $select->union($select1, $select2); That doesn't work of course. To explain what I need. I need to use UNION() to merge 2 tables in a SELECT query, I know I could just do: $select = "$select1 UNION $select2"; The problem is that would return a string and I need to get a select object so I can use it

How to write UNION in Doctrine 2.0

巧了我就是萌 提交于 2019-12-17 18:37:36
问题 How to write this SQL query in Doctrine 2.0 (and fetch results)? (SELECT 'group' AS type, CONCAT(u.firstname, " ", u.surname) as fullname, g.name AS subject, user_id, who_id, group_id AS subject_id, created FROM group_notification JOIN users u ON(who_id = u.id) JOIN groups g ON(group_id = g.id) ) UNION (SELECT 'event' AS type, CONCAT(u.firstname, " ", u.surname) as fullname, e.name AS subject, user_id, who_id, event_id AS subject_id, created FROM event_notification JOIN users u ON(who_id = u

UNION the results of multiple stored procedures

南楼画角 提交于 2019-12-17 09:08:26
问题 I have a stored procedure I need to call several different times passing in different paramaters each time. I would like to collect the results as a single dataset. Is something like this possible ... exec MyStoredProcedure 1 UNION exec MyStoredProcedure 2 UNION exec MyStoredProcedure 3 I tried using the syntax above but got the error ... Incorrect syntax near the keyword 'UNION' The stored procedures I am dealing with are pretty complex and sort of a "black box" to me, so I cannot get into

Selecting 2 tables from 2 different databases (ACCESS)

大憨熊 提交于 2019-12-17 07:54:56
问题 here is the connection i have strCon="DBQ=" & Server.Mappath("db.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};PWD=password;" set adoCon=server.createobject("adodb.connection") adoCon.Open strCon so in order to work with the 2 databases i have 2 adoCon and when i do the select i select from each db i need now for the problem... in this situation i will be able only to get all the info from one and then from the other one. but what i want is to be able to put the together. db1.tblcats has

Help me out with this MySql full outer join (or union)

拥有回忆 提交于 2019-12-14 04:14:02
问题 This is coming from converting MSSQL to MySql. The following is code I'm trying to get to work: CREATE TEMPORARY TABLE PageIndex ( IndexId int AUTO_INCREMENT NOT NULL PRIMARY KEY, ItemId VARCHAR(64) ); INSERT INTO PageIndex (ItemId) SELECT Paths.PathId FROM Paths, ((SELECT Paths.PathId FROM AllUsers, Paths WHERE Paths.ApplicationId = @ApplicationId AND AllUsers.PathId = Paths.PathId AND (@Path IS NULL OR Paths.LoweredPath LIKE LOWER(@Path))) AS SharedDataPerPath UNION -- This used to be a

Is this a possible Oracle bug or am I missing something?

无人久伴 提交于 2019-12-14 03:52:07
问题 Database is Oracle 10.2.0.1.0 - 64bit running on Red Hat Enterprise Linux ES release 4 (Nahant Update 8) In SQL*Plus following code run perfectly: var comment_id number exec :comment_id := 3052753 select e.label as doc_name, e.url, i.item_id, 'multi' as form_type from cr_items i, cr_extlinks e where i.parent_id = :comment_id and e.extlink_id = i.item_id UNION select null as doc_name, utl_raw.cast_to_varchar2(DBMS_LOB.SUBSTR(r.content, 2000, 1)) as url, r.item_id, 'single' as form_type from cr