union

Every derived table must have its own alias - error from combination descending MySQL

◇◆丶佛笑我妖孽 提交于 2019-12-23 09:06:00
问题 I want to order one mysql table by two strtotime timestamps from two different columns. I've got the following mysql command: SELECT * FROM ( (SELECT '1' AS `table`, `vid_req_timestamp` AS `timestamp`, `title` FROM `movies` WHERE `vid_req` = '1') UNION (SELECT '2' AS `table`, `ost_req_timestamp` AS `timestamp`, `title` FROM `movies` WHERE `ost_req` = '1') ) ORDER BY `timestamp` DESC This gives me an error: #1248 - Every derived table must have its own alias I want to combine vid_req_timestamp

Case statement to determine if I should union

我的梦境 提交于 2019-12-23 07:57:54
问题 I currently want to do some sort of conditional union. Given the following example: SELECT age, name FROM users UNION SELECT 25 AS age, 'Betty' AS name Say I wanted to only union the second statement if the count of 'users' was >=2 , otherwise do not union the two. In summary I want to append a table with a row if the table only has 2 or more values. 回答1: You could use an ugly hack something like this, but I think Tim's answer is better: SELECT age, name FROM users UNION ALL SELECT 25 AS age,

How to get combined result in MySQL with query optimization?

筅森魡賤 提交于 2019-12-23 04:39:14
问题 I have table like, id | OpenDate | CloseDate ------------------------------------------------ 1 | 2013-01-16 07:30:48 | 2013-01-16 10:49:48 2 | 2013-01-16 08:30:00 | NULL I needed to get combined result as below id | date | type --------------------------------- 1 | 2013-01-16 07:30:48 | Open 1 | 2013-01-16 10:49:48 | Close 2 | 2013-01-16 08:30:00 | Open I used UNION to get above output (can we achieve without UNION?) SELECT id,date,type FROM( SELECT id,`OpenDate` as date, 'Open' as 'type'

Select new or returning items for a specified year

◇◆丶佛笑我妖孽 提交于 2019-12-23 03:38:12
问题 I have a table which looks roughly like this: +---------------------+----------+ | date | item | +---------------------+----------+ | 2008-11-30 11:15:59 | Plums | | 2012-11-08 19:42:37 | Lemons | | 2013-01-30 18:58:07 | Apples | | 2013-02-12 13:44:45 | Pears | | 2014-06-08 11:46:48 | Apples | | 2014-09-01 20:28:03 | Oranges | +---------------------+----------+ I would now like to select items for two cases: 1) I'd like to select all distinct items for this year (or a different specified year

PDO UNION with ? not working

不羁的心 提交于 2019-12-23 03:04:42
问题 I am new to SQL and PDO and PHP so I know I am asking a lot of myself. Still nothing ventured... I want to combine the results of two queries and am using aliases to make the column names the same for the UNION query. I have tried all sorts of reducing till there is nothing left to reduce, there are many more in the actual result I need for my app. I have the following code by can't think why it is not working. Both queries work on their own but I get nothing when I combine them with a UNION.

Union with NHibernate and Criteria?

瘦欲@ 提交于 2019-12-23 02:59:09
问题 Union with NHibernate and Criteria: Is it possible in Criteria or QueryOver? If not, is there any other way to achieve a union of two result within the same query? 回答1: You can't do a union directly, but you can do two future queries and union the results in code: var resultSet1 = this.Session.CreateCriteria<A>().Future<A>(); var resultSet2 = this.Session.CreateCriteria<B>().Future<B>(); After this, when either result set is enumerated, NHibernate will issue a single query to the database

Performance comparison with postgresql : left join vs union all

柔情痞子 提交于 2019-12-23 01:46:57
问题 I want to know what is the best and the fastest solution between a "left outer join" and an "union all". The database is a PostgreSQL. Query with an UNION ALL : SELECT * FROM element, user WHERE elm_usr_id = usr_id UNION ALL SELECT * FROM element WHERE elm_usr_id ISNULL; Query with a LEFT OUTER JOIN : SELECT * FROM element LEFT OUTER JOIN user ON elm_usr_id = usr_id; 回答1: Your two queries may not produce the same result. Your query with UNION ALL returns rows that matches plus rows that not

What is the difference between structures containing bool vs uint when using PInvoke?

半城伤御伤魂 提交于 2019-12-22 22:53:28
问题 Ok, I'm now very confused. After my last question had several people comment about changing bool to uint I verified they are the same size by: Console.WriteLine("sizeof bool = {0}", Marshal.SizeOf(typeof(bool))); Console.WriteLine("sizeof uint = {0}", Marshal.SizeOf(typeof(uint))); Which of course prints: sizeof bool = 4 sizeof uint = 4 That said, I then broke down and gave their suggestions a try anyway... Changing a single bool inside a structure to a uint. What I can't figure out for the

Tsql union query

一世执手 提交于 2019-12-22 17:54:24
问题 I’m looking for an efficient way to query a table. The table structure is: CREATE TABLE [dbo].[CaseManager]( [CaseID] [int] IDENTITY(1,1) NOT NULL, [SystemUserCreatedBy] [int] NULL, [SystemUserAssignee] [int] NULL, CONSTRAINT [PK_Case] PRIMARY KEY CLUSTERED ( [CaseID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY] ) ON [PRIMARY] The query should return for every caseID and userid

SQL: Union of two tables which don't have full column match

那年仲夏 提交于 2019-12-22 10:07:08
问题 I have a table_A which has a set of column A1 , A2 and a table_b which has a set of columns B1 , B2 It happens that A2=B1 but the rest of the columns don't match (and are not supposed to). I would like to append the table so I use UNION ALL For non matching columns, I use null as COLUMN_NAME , on both sides of the UNION statement CREATE VIEW MY_VIEW AS SELECT TABLE_A.A1, TABLE_A.A2, null as B2 from TABLE_A union all SELECT null as A1, TABLE_B.B1 as A2, TABLE_B.B2 as B2 from TABLE_B; which