Re: Building WHERE SQL clauses

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

 



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



""Bastien Koert"" <phpster@xxxxxxxxx> wrote in message 
news:d7b6cab70809151946h42b626cfr37496eb2583b863a@xxxxxxxxxxxxxxxxx
> On Mon, Sep 15, 2008 at 1:33 PM, Stephen Wellington <
> wellingtonsteve@xxxxxxxxx> wrote:
>
>> You probably want something like this:
>>
>> SELECT * FROM chico as c, harpo as h WHERE c.operator = "Bill" OR
>> c.operator =
>> "Jessica" OR h.operator = "Bill" OR h.operator ="Jessica"
>>
>> However if those tables really are identical I would suggest having a
>> good look at your
>> database design to see if it can be normalised or something...
>>
>> Stephen Wellington
>>
>> On Mon, Sep 15, 2008 at 4:06 PM, Mike Sullivan <mjsulliv@xxxxxxx> wrote:
>> > Hello all.  I'm using PHP to build a query for a database that consists
>> of
>> > multiple tables, all with identical attribues.  A typical syntax try
>> looks
>> > like this:  SELECT * FROM chico, harpo WHERE operator = "Bill" OR
>> operator =
>> > "Jessica"
>> >
>> > MySQL responds with this:  Couldn't execute query.Column 'operator' in
>> where
>> > clause is ambiguous
>> >
>> > I was hoping that since the tables are identical all I would need to do
>> is
>> > list the attribute values not have to append them to the table names. 
>> > Is
>> > there any way to do this?  Perhaps with a setting in MySQL or a 
>> > different
>> > syntax (JOIN, UNION, ...)?  If not are there available some canned code
>> > snippets that build these types of strings from values passed in the
>> $_POST
>> > array.  Thanks for any insights on this. --- Mike
>> >
>> >
>> >
>> > --
>> > PHP Database Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>>
>> if the structures and fields are truly the same you can UNION the queries
>
> select * from chico where operator in('Jessica','William')
> union
> select * from harpo where operator in('Jessica','William')
>
> But as suggested, if they are truly similar, the db needs to be looked for
> design
>
> -- 
>
> Bastien
>
> Cat, the other other white meat
> 



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