SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql insert select

    Generally mysql does
    Code MySQL:
    INSERT INTO user (id, name, email, passwd, site) SELECT idm, user_name, email, pass, site_url FROM members WHERE id>100 AND id<200

    But I want a query where `site` column of user table will insert a static string fixed my me, not from `members` table

    something like
    (just for easy to understand)
    Code MySQL:
    INSERT INTO user (id, name, email, passwd) SELECT idm, user_name, email, pass FROM members WHERE id>100 AND id<200, SET site='my fixed site url'

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    695
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    insert into user (id, name, email, passwd,site) 
    select idm, user_name, email, pass, 'my fixed site url'
      from members 
     where id > 100
       and id < 200

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    It's easier than you think
    Code MySQL:
    INSERT INTO user (id, name, email, passwd, site) 
    SELECT 
        idm
      , user_name
      , email
      , pass
      , 'my fixed site url'
    FROM members 
    WHERE id>100 
    AND id<200

    Swampboogie was quicker..


Bookmarks

Posting Permissions

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