[prev in list] [next in list] [prev in thread] [next in thread]
List: mysql
Subject: Re: Interresting update problem
From: "Dan Buettner" <drbuettner () gmail ! com>
Date: 2007-06-27 13:58:02
Message-ID: c97ba7a80706270658k2c7bbe9ape93a8675b5c8954e () mail ! gmail ! com
[Download RAW message or body]
What I've done in situations like this is write SQL that generates the SQL I
need. I then pipe out to a file and pipe it back in, or just pipe from one
instance of mysql to another.
Example SQL:
SELECT
CONCAT('UPDATE main SET ', field, ' = ', id, ';')
AS update_sql
FROM map
Example command to accomplish on one step:
mysql -u user -ppass -D db -e "the above sql" | mysql -u user -ppass -D db
HTH,
Dan
On 6/27/07, Mogens Melander <mogens@fumlersoft.dk> wrote:
>
> Hi all,
>
> I'm trying to wrap my brain around folowing problem.
>
> table main(code, field_1, field_2, field_3, , , field_51)
>
> 111, 'X', '', 'X',,,
> 222, '', '', 'X',,,
> 333, '', 'X', '' ,,,
> 444, '', '', '' ,,,
> 555, 'X','X', '' ,,,
>
> table map(id, field)
>
> 1, 'field_1'
> 5, 'field_2'
> 9, 'field_3'
> ....
> ....
> 86, 'field_51'
>
> The exercise is: replace 'X' with map.id in main.<map.field>
>
> main.code and map.id are primary keys, all other are varchar.
>
> Hmm, did that make any sense?
>
> --
> Later
>
> Mogens Melander
> +45 40 85 71 38
> +66 870 133 224
>
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=drbuettner@gmail.com
>
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic