Все вопросы: [union]

80 вопросов

13
голосов
4ответов
11152 просмотров

rails union hack, how to pull two different queries together

I have a query which searches two separate fields in the same table... looking for locations which are most likely a specific city, but could also be a country... ie the need for two fields. Table looks like: Country City Germany Aachen USA Amarillo USA Austin Result: Ke...

2
голосов
3ответов
6605 просмотров

Index on UNION query?

i've got this union query: (SELECT INSTALLER, INSTALLTIME, RESULT, JOBNUMBER, HONAME, ADDRESS, CITY, STATE, ZIP, NOTES, SMNOTES, '' as priority, PAFS, upsell, TERM, MMRUPGRADE, WARRANTY, EFT FROM ACCOUNTS WHERE INSTALLDATE = '$date' && FUNDINGSTATUS !='DEAD') UNION (SELECT technician,...

0
голосов
10ответов
287 просмотров

What kind of SQL join is this?

Say for some reason I have employees in two separate tables, employee1 and employee2 I just want to add them together, as if they are stacked on top of each other. something like: select all from employee1 and employee2 where name = bubba i know im generalizing, this will be in postgres even...

1
голосов
4ответов
524 просмотров

SQL query to collect entries from different tables - need an alternate to UNION

I'm running a sql query to get basic details from a number of tables. Sorted by the last update date field. Its terribly tricky and I'm thinking if there is an alternate to using the UNION clause instead...I'm working in PHP MYSQL. Actually I have a few tables containing news, articles, photos, ...

2
голосов
3ответов
8052 просмотров

Getting rid of duplicate results in MySQL query when using UNION

I have a MySQL query to get items that have had recent activity. Basically users can post a review or add it to their wishlist, and I want to get all items that have either had a new review in the last x days, or was placed on someone's wishlist. The query goes a bit like this (slightly simplifi...

0
голосов
3ответов
168 просмотров

Combining 2 different but fairly similar tables

I have 2 tables that are similar but not the same so a union is not a possibility. I need to combine the tables bearing in mind there's about 40 columns where only 20 are common to both. Any ideas on the best approach? Table1 ActivityCategory ActivityType Nationality Language ----------...

4
голосов
3ответов
2048 просмотров

How do I select one parent row and additional rows for its children without a UNION?

I have a parent and child table and want to create a select statement that, given a parent id, returns a row for that parent and additional rows for every child. Doing a left join is not giving me a row for the parent by itself when one or more children exist. I know this can be done with a UNION...

0
голосов
3ответов
129 просмотров

Why only one record after union?

mysql> select count(id) total from applicants; +-------+ | total | +-------+ | 0 | +-------+ 1 row in set (0.00 sec) mysql> select count(id) total from jobs; +-------+ | total | +-------+ | 0 | +-------+ 1 row in set (0.00 sec) mysql> select count(id) total from applicants unio...

5
голосов
4ответов
43735 просмотров

SQL: cascade UNION and JOIN

I have a union opertaion between two tables SELECT ID_1, name_1, surname_1, FROM T_ONE UNION SELECT ID_2, name_2, surname_2 FROM TABLE_2 I want to join the result of this UNION operation with another table or even with all TABLE_1. How can I handle this new ta...

65
голосов
1ответов
68658 просмотров

Combining UNION and LIMIT operations in MySQL query

I have a Jobs and a Companies table, and I want to extract 20 jobs that meet the following criteria: Jobs only from two (2) named companies There can at most be 10 jobs per company I have tried the following SELECT with UNION DISTINCT, but the problem is that the LIMIT 0,10 applies to the ...

18
голосов
4ответов
10451 просмотров

SQL - Identifying source table from UNION query

I'm building an RSS feed in PHP which uses data from three separate tables. The tables all refer to pages within different areas of the site. The problem I have is trying to create the link fields within the XML. Without knowing which table each record has come from, I cannot create the correc...

4
голосов
4ответов
7647 просмотров

MySQL Union Query w/ Left Join - Order By Error?

We have a Union Query. Here's a basic (similar) example: SELECT a.Name, b.Info FROM a LEFT JOIN b ON (a.ID = b.ID) WHERE a.Name LIKE "a%" UNION SELECT a.Name, b.Info FROM a LEFT JOIN b ON (a.ID = b.ID) WHERE a.Name LIKE "b%" ORDER BY a.Name, b.Info; I am receiving an error that says "Unknow...

1
голосов
1ответов
618 просмотров

Linq and nullable key relationships affecting UNION operation

Here is an example: Lets say I have 3 tables, Countries, People and Cities. City records have a non-nullable foreign key field identifying a country. People records have a nullable foreign key field identifying a country - they may be from an Eastern European country that no longer exists. I wa...

20
голосов
3ответов
14449 просмотров

Which is faster: Union or Concat?

Which is faster: Union or Concat? I don't care about the order of the elements. Enumerable.Union Method Enumerable.Concat Method

1
голосов
1ответов
253 просмотров

How can I "compress" my tree into aggregate data on up the hierarchy in Oracle?

I have to get a list of limits for a the sub-parts of a level 1part. Limits for some parts are null, and for those null parts, I have to query the level 2 parts that are on that part and give the MIN of the limits of those level 2 parts. For some of the level 2 parts, I have to get the MIN of t...

5
голосов
4ответов
7955 просмотров

How to union queries from the same table in MySQL

I have two sets of results: SELECT name, count(appearance) as countA from table where results = '1' SELECT name, count(appearance) as countB from table where results = '2' And I wanted to combine them side by side, like this: +---------+---------+---------+ | col_1 | countA | countB | +--...

4
голосов
6ответов
12532 просмотров

Zend Framework Select Objects And UNION()

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 nee...

0
голосов
2ответов
111 просмотров

MySQL query for ALL search terms in index

I have a table of employees and their schedule, like so: Emp_Name | Date -------- ----- Smith | 08-01-2009 Jones | 08-01-2009 Goodman | 08-02-2009 Smith | 08-02-2009 Jones | 08-02-2009 Goodman | 08-03-2009 How would I write a query so that the results were only employee names of...

9
голосов
4ответов
11182 просмотров

What is the difference between group by, distinct, Union for selecting distinct values for multiple columns?

This question explained about a way of getting distinct combination of multiple columns. But I want to know the difference between the methods of DISTINCT, UNION, GROUP BY keyword method for this purpose. I am getting different results when using them. My queries are like this Query 1. select c...

44
голосов
3ответов
120984 просмотров

Using union and count(*) together in SQL query

I have a SQL query, looks something like this: select name, count (*) from Results group by name order by name and another, identical which loads from a archive results table, but the fields are the same. select name, count (*) from Archive_Results group by name order by name How would I co...

3
голосов
3ответов
1818 просмотров

MySQL performance – Multiple queries or one inefficient query?

I have three tables, each contain some common information, and some information that is unique to the table. For example: uid, date are universal among the tables, but one table can contain a column type while the other contains currency. I need to query the database and get the last 20 entries (...

2
голосов
4ответов
272 просмотров

SQL: SELECT n% with pictures, (100-n)% without pictures

we have a DB which stores users who may have pictures. I am looking for an elegant way in SQL to get the following results: Select n users. Of those n users e.g. 60% should have an associated picture and 40% should not have a picture. If there are less than 60% users having a picture the result ...

1
голосов
1ответов
100 просмотров

merging data bt tables in mysql

I have three tables with the following structure: tb1: id(AI, PK), uid, date, text tb2: id(AI, PK), uid, date, text ... and so on I have to keep them separate because of additional unqiue data that each table has. I'd like to execute a query that will merge and get me the last 20 entries (ie, ...

6
голосов
2ответов
10364 просмотров

Why doesn't the Union function in LINQ remove duplicate entries?

I'm using VB .NET and I know that Union normally works ByRef but in VB, Strings are generally processed as if they were primitive datatypes. Consequently, here's the problem: Sub Main() Dim firstFile, secondFile As String(), resultingFile As New StringBuilder firstFile = My.Computer.Fi...

34
голосов
10ответов
4538 просмотров

What's a good, generic algorithm for collapsing a set of potentially-overlapping ranges?

I have a method that gets a number of objects of this class class Range<T> { public T Start; public T End; } In my case T is DateTime, but lets use int for simplicity. I would like a method that collapses those ranges into ones that cover the same "area" but that do not overlap. ...

8
голосов
3ответов
11527 просмотров

Drupal Views combine 2 columns into 1?

I've got two content types, both have a node title and a document attachment, the doc attachment fields are different names (being from two different content types). In my view, I'm displaying the node title and the file name in a table. The node titles are great all in one column, but the two c...

49
голосов
3ответов
296969 просмотров

Combine two tables for one output

Say I have two tables: KnownHours: ChargeNum CategoryID Month Hours 111111 1 2/1/09 10 111111 1 3/1/09 30 111111 1 4/1/09 50 222222 1 3/1/09 40 111111 2 4/1/09 50 UnknownHours: Char...

1
голосов
2ответов
1124 просмотров

Ordering FREETEXTTABLE result UNIONed with standard SELECT by Rank

I had a working FREETEXTTABLE query that searched for a @searchString. I now need to UNION that with another simple query that tries to parse the @searchString into an INT, and if it succeeds, filtering the table by looking for the row with PK equal to the parse @searchString. Previously, I coul...

60
голосов
14ответов
276086 просмотров

Combine two tables that have no common fields

I want to learn how to combine two db tables which have no fields in common. I've checked UNION but MSDN says : The following are basic rules for combining the result sets of two queries by using UNION: The number and the order of the columns must be the same in all queries. The data types must...

1
голосов
1ответов
1881 просмотров

Trying to speed up a SQLITE UNION QUERY

I have the below SQLITE code SELECT x.t, CASE WHEN S.Status='A' AND M.Nomorebets=0 THEN S.PriceText ELSE '-' END AS Show_Price FROM sb_Market M LEFT OUTER JOIN (select 2010 t union select 2020 t union select 2030 t union select 2040 t union select 2050 t union select 2060 t union select 2070 t )...