Re: Building WHERE SQL clauses

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

 



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/



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