Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: ambiguous col

  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    ambiguous col

    id is key

    Code:
    insert into test
    select t1.id,@variable := t1.col from test t1
    on duplicate key update col = col + @variable
    same with this

    Code:
    insert into test t
    select t1.id,t1.col from test t1
    on duplicate key update t.col = t.col + t1.col
    SQL Error (1052): Column 'col' in field list is ambiguous

    ?
    Last edited by BubikolRamios; 03-26-2013 at 12:31 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,200
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Yes, I got that, too.

    But here's a sneaky way around it:
    Code:
    CREATE VIEW testview AS
    SELECT id, col AS viewcol FROM test;
    
    INSERT INTO test
    SELECT id, viewcol FROM testview
    ON DUPLICATE KEY UPDATE col = col + viewcol;
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •