union-all

Using Union All and Order By in MySQL

穿精又带淫゛_ 提交于 2020-01-11 09:42:13
问题 I've 2 tables: create table advertised_products(id int,title varchar(99),timestamp timestamp); insert advertised_products select 1,'t1',curdate(); create table wanted_products(id int,title varchar(99),timestamp timestamp); insert wanted_products select 1,'t1',now(); I'm using this query to get the records: ( SELECT ap.*, 'advertised' as type FROM advertised_products as ap ) union all ( SELECT wp.*, 'wanted' as type FROM wanted_products as wp ) ORDER BY timestamp desc limit 3 But it gives

mySQL INNER JOIN together with UNION ALL

别说谁变了你拦得住时间么 提交于 2020-01-07 02:55:06
问题 I have a table with rows that's grouped if the date and the category 'bar' matches, now I need to INNER JOIN these with another table and use a WHERE answer = '2' from that table, but I don't know how to do that. SELECT category, date, client FROM sbs_events WHERE category <> 'bar' UNION ALL SELECT category, date, MIN(client) AS client FROM sbs_events WHERE category = 'bar' GROUP BY category, date I've made a SQL Fiddle The thing I need to add to the fiddle is INNER JOIN sbs_userEvents ON sbs

MS Access Create Table is Truncating Memo Field

戏子无情 提交于 2020-01-05 04:44:29
问题 Access 2013 I have several logs that are consolidated using a UNION ALL query that is written by a macro. The resulting Query is as follows: SELECT [zData Navy FY15 AFS].[Journal Voucher ID], Count([zData Navy FY15 AFS].[Journal Voucher ID]) AS [Record Count], First([zData Navy FY15 AFS].[Table Source]) AS [Table Source], First([zData Navy FY15 AFS].[dBranch]) AS [dBranch], First([zData Navy FY15 AFS].[DB_ID]) AS [DB_ID], First([zData Navy FY15 AFS].[Source]) AS [Source], First([zData Navy

Prevent sort result of union in entity framework

妖精的绣舞 提交于 2019-12-25 08:19:54
问题 In SQL server union , result is sorted based on primary key column. I want to prevent this behavior in entity framework. In this post, @praveen has explained how to do this in pure sql. But I want to do this in entity framework. My code : public virtual ActionResult Search(string keyword) { var products = _db.Products .Where(x => x.IsActive) .AsQueryable(); var productExactlyTitle = products.Where(x => x.Title == keyword); var productStartTitle = products.Where(x => x.Title.StartsWith(keyword

C# Linq UNION syntax on 2 complex queries

自闭症网瘾萝莉.ら 提交于 2019-12-25 00:10:25
问题 This is pretty complicated for a person just learning Linq! I asked how to JOIN and GROUP BY in this question and a BIG SHOUT OUT to TriV for his explicit and very helpful answer. Now, I want to take my already very complicated query and create a UNION to a similar query. I have below, 2 separate SQL queries that I have put into 1 query using a UNION clause. The first query joins two tables. But the second query is against only one table, because it is for unassigned assets that are not

Why is UNION ALL with and without parenthesis behaving different?

淺唱寂寞╮ 提交于 2019-12-24 16:33:30
问题 I have this query implemented in two ways: SELECT race1, mode1 FROM organization WHERE condition = 1 LIMIT 1 UNION ALL (SELECT race2, mode2 FROM organization WHERE condition = 1 LIMIT 1) UNION ALL (SELECT race, mode FROM organization_new WHERE PK_Id = 1) And SELECT race1, mode1 FROM organization WHERE condition = 1 LIMIT 1 UNION ALL SELECT race2, mode2 FROM organization WHERE condition = 1 LIMIT 1 UNION ALL SELECT race, mode FROM organization_new WHERE PK_Id = 1 As you can see, the difference

How to combine rows of 2 tables having some columns same and some different

陌路散爱 提交于 2019-12-24 11:42:11
问题 I have two tables for user posts, one for text post and one for multimedia post, the structure of both tables is as follows. table text_post +--------+--------------+-----------+-----------+-----------------+-----------+ | postid | post_content | post_user | post_type | post_visibility | post_date | +--------+--------------+-----------+-----------+-----------------+-----------+ table multimedia_post +-------+------------+--------+---------+---------+---------------+---------+ |post_id|post

Why using OR condition instead of Union caused a performance Issue

喜夏-厌秋 提交于 2019-12-23 05:45:10
问题 Hi I have below query in an SP @CrmContactId is a parameter to the SP. Select distinct A.PolicyBusinessId, A.PolicyDetailId from TPolicyBusiness A inner join TPolicyOwner B on a.PolicyDetailId=b.PolicyDetailId Left Join TAdditionalOwner C on c.PolicyBusinessId=A.PolicyBusinessId where (b.CRMContactId = @CRMContactId) we made a new change and introduced an OR condition Select distinct A.PolicyBusinessId, A.PolicyDetailId from TPolicyBusiness A inner join TPolicyOwner B on a.PolicyDetailId=b

UNION ALL two SELECTs with different column types - expected behaviour?

≡放荡痞女 提交于 2019-12-22 08:15:22
问题 What is the expected behaviour due to SQL Standard when we perform UNION on two tables with different data types: create table "tab1" ("c1" varchar(max)); create table "tab2" ("c3" integer); insert into tab1 values(N'asd'), (N'qweqwe'); insert into tab2 values(123), (345); select c_newname as myname from ( select "c1" as c_newname from "tab1" union all select "c3" from "tab2" ) as T_UNI; MS SQL Server gives Conversion failed when converting the varchar value 'asd' to data type int. but what

SQL Server, Using UNION ALL for multiple tables then paging implementation

≡放荡痞女 提交于 2019-12-21 07:25:07
问题 I need help also about paging and using UNION ALL for multiple tables: How do i implement an optimized paging when joining multiple tables using UNION ALL and returning only specific number of rows... declare @startRow int declare @PageCount int set @startRow = 0 set @PageCount = 20 set rowcount @PageCount select Row_Number() OVER(Order by col1) as RowNumber, col1, col2 from ( select col1, col2 from table1 where datetimeCol between (@dateFrom and @dateTo) union all select col1, col2 from