dbTalk Databases Forums  

in a subselect, refer to value outside parentheses?

comp.databases.mysql comp.databases.mysql


Discuss in a subselect, refer to value outside parentheses? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Steven Lefevre
 
Posts: n/a

Default in a subselect, refer to value outside parentheses? - 11-03-2010 , 02:28 PM






I want to do an update to a field that I left blank when I left it out
of a mass insert. However, I'm having trouble thinking of how to
phrase it. Basically I want to refer to a value outside the
parentheses of a subselect.

Something like this:

UPDATE table SET text_field_1 = ( SELECT text_field_2 FROM other_table
WHERE id = **current row in update statement, outside parens**.id )

How do I do it?

Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: in a subselect, refer to value outside parentheses? - 11-03-2010 , 02:47 PM






On 11/3/2010 4:28 PM, Steven Lefevre wrote:
Quote:
I want to do an update to a field that I left blank when I left it out
of a mass insert. However, I'm having trouble thinking of how to
phrase it. Basically I want to refer to a value outside the
parentheses of a subselect.

Something like this:

UPDATE table SET text_field_1 = ( SELECT text_field_2 FROM other_table
WHERE id = **current row in update statement, outside parens**.id )

How do I do it?
Not knowing your table layout or data, it's a guess, but maybe something
like:

UPDATE table
SET text_field_1 =
(SELECT text_field_2
FROM other_table
WHERE other_table.id = table.id)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #3  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: in a subselect, refer to value outside parentheses? - 11-04-2010 , 02:18 AM



El 03/11/2010 21:28, Steven Lefevre escribió/wrote:
Quote:
I want to do an update to a field that I left blank when I left it out
of a mass insert. However, I'm having trouble thinking of how to
phrase it. Basically I want to refer to a value outside the
parentheses of a subselect.

Something like this:

UPDATE table SET text_field_1 = ( SELECT text_field_2 FROM other_table
WHERE id = **current row in update statement, outside parens**.id )
The syntax can be one of these:

UPDATE invoice iv
INNER JOIN customer ct ON iv.customer_id=ct.customer_id
SET iv.vat_number=ct.vat_number;

UPDATE invoice iv, customer ct
SET iv.vat_number=ct.vat_number
WHERE iv.customer_id = ct.customer_id;

UPDATE invoice iv
SET vat_number=(
SELECT ct.vat_number
FROM customer ct
WHERE iv.customer_id=ct.customer_id
);

Last example looks similar to your query.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.