Re: Building WHERE SQL clauses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Chris" <dmagick@xxxxxxxxx> wrote in message 
news:48D0352A.9060708@xxxxxxxxxxxx
> Mike Sullivan wrote:
>> Hi all thanks for the responses! What I have is a 6 table db that has 
>> each
>>
>> table created from the output of 6 identical laboratory machines (chico,
>>
>> harpo, ...). The out put is a text file which I import as a table named
>>
>> after the machine. I do realize that one solution is to add the machine
>>
>> name as a attribute and concatenate the tables together. I'm going to 
>> weigh
>>
>> that change against Bastien's suggestion of UNIONing the selects.
>>
>> I must admit that I'm still rather weak in the SQL department and did try 
>> a
>>
>> solution of:
>>
>> SELECT * FROM (chico UNION harpo) WHERE operator = "Bill" OR operator =
>>
>> "Jessica" but that apparently is a SQL syntax error.
>>
>> Thanks again for the insight and any other suggestions you might 
>> have. ---  Mike
>
> A UNION combines the results from query 1 and query 2 together.
>
> For example:
>
> select * from chico where operator in ('Bill', 'Jessica')
> union
> select * from harpo in ('Bill', 'Jessica')
>
> will:
>
> - get all rows from the chico table where the operator is Bill or Jessica
> - get all rows from the harpo table where the operator is Bill or Jessica
> - remove duplicate results
> - return the results
>
>
> A UNION ALL will skip the 'remove duplicates' step:
>
> - get all rows from the chico table where the operator is Bill or Jessica
> - get all rows from the harpo table where the operator is Bill or Jessica
> - return the results
>
> If query 1 AND query 2 don't return the results you want, then a union
> is the wrong type of query to run.
>
> http://dev.mysql.com/doc/refman/5.0/en/union.html
>
> I'm confused about what you're trying to get out of the results, can you
> explain further and give an example of the data you have, and the result 
> you want to return?
>
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>

>From what I've experimented around with from the suggestions gathered here, 
a union is what I want.  and had tried that but using table names as the 
parameters to UNION not the results of query's as you show above.   I've got 
a prototype like this now working but I've pretty much decided to go back 
and redo the java program that parses the text files and builds the 
LOAD-able files so that it adds a machine name attribute and concatenates 
the data in one file.

--- Mike 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux