Re: Building WHERE SQL clauses
| From: | Chris | Date: | Tue, 16 Sep 2008 22:37:30 +0000 |
| Subject: | Re: Building WHERE SQL clauses | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-45426@lists.php.net to get a copy of this message | ||
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. --- MikeA 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/