Welcome Guest, Not a member yet? Register   Sign In
Multi-table write with single query - is it possible?
#1

[eluser]seanloving[/eluser]
I can perform a multi-table read like this...
Code:
$this->CI->db
            ->select( " customer_id,
                        customer_type,
                        organization_name,
                        CONCAT( lastname, ', ', firstname ) AS contact,
                        CONCAT( organization_city, ', ', organization_state ) AS location,
                        organization_telephone,
                        organization_email",
                        FALSE)
            ->from('organizations')
            ->join('customers', 'customers.organization_id = organizations.organization_id', 'left')
            ->join('contacts', 'contacts.contact_id = customers.contact_id', 'left')
            ->group_by('organization_name')->get()->result_array();
but how can I UPDATE in a single query ??

Thanks
Sean Loving
#2

[eluser]Sinclair[/eluser]
I have done it in SQL Server, using Views with "Instead" Triggers. In MySQL I never done it.
#3

[eluser]danmontgomery[/eluser]
Same way you do a select.

http://dev.mysql.com/doc/refman/5.0/en/update.html

Code:
UPDATE table1 LEFT JOIN table2 ON table2.table1_id = table1.id SET table1.value1 = "Some Value", table2.value2 = "Some Other Value" WHERE table1.value3 = "Some Third Value";

I don't believe active record supports joins in update statements, however.
#4

[eluser]seanloving[/eluser]
[quote author="noctrum" date="1266372163"]Same way you do a select.

http://dev.mysql.com/doc/refman/5.0/en/update.html

Code:
UPDATE table1 LEFT JOIN table2 ON table2.table1_id = table1.id SET table1.value1 = "Some Value", table2.value2 = "Some Other Value" WHERE table1.value3 = "Some Third Value";

I don't believe active record supports joins in update statements, however.[/quote]

Since active record can't, this is what I need. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB