About 169,000 results
Open links in new tab
  1. sql - Understanding union query - Stack Overflow

    Mar 10, 2021 · UNION ALL - Includes duplicates. UNION - Excludes duplicates. A UNION operation is different from a JOIN: A UNION concatenates result sets from two queries. But a UNION does not …

  2. SQL Server: How to use UNION with two queries that BOTH have a …

    Given: Two queries that require filtering: select top 2 t1.ID, t1.ReceivedDate from Table t1 where t1.Type = 'TYPE_1' order by t1.ReceivedDate desc And: select top 2 t2.ID from Table t2 w...

  3. sql - UNION with WHERE clause - Stack Overflow

    Mar 20, 2017 · I'm doing a UNION of two queries on an Oracle database. Both of them have a WHERE clause. Is there a difference in the performance if I do the WHERE after UNIONing the queries …

  4. How to order by with union in SQL? - Stack Overflow

    Per the SQL Standard, the order of results is undefined barring an explicit order by clause. That first select in your example probably returns its results in the order returned by the subselect, but it is not …

  5. How to use multiple with statements along with UNION ALL in SQL?

    How to use multiple with statements along with UNION ALL in SQL? Asked 11 years, 4 months ago Modified 2 years, 7 months ago Viewed 42k times

  6. How to use order by with union all in sql? - Stack Overflow

    Mar 18, 2013 · SELECT * FROM (SELECT * FROM TABLE_A ORDER BY COLUMN_1)DUMMY_TABLE UNION ALL SELECT * FROM TABLE_B It results in the following …

  7. Sql Server union with If condition - Stack Overflow

    Nov 1, 2012 · Sql Server union with If condition Asked 13 years, 1 month ago Modified 5 years, 2 months ago Viewed 74k times

  8. WHERE statement after a UNION in SQL? - Stack Overflow

    Mar 27, 2011 · Basically, the UNION is looking for two complete SELECT statements to combine, and the WHERE clause is part of the SELECT statement. It may make more sense to apply the outer …

  9. Select from union in SQL Server - Stack Overflow

    SELECT A FROM ( SELECT A, B FROM TableA UNION SELECT A, B FROM TableB ) WHERE B > 'some value' Am I missing anything or making an assumption about how this works? I'm using …

  10. SQL UNIONs that use the WITH statement - Stack Overflow

    Mar 21, 2011 · The WITH statement indicates that the query expressed within the AS clause is a Common Table Expression (CTE). If you're asking if you can write more than one query that uses a …