SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Updating one table from another

    This worked for me, sorry.
    Code:
       UPDATE TableA a 
         SET a.lastFirstMiddle = CONCAT(TRIM(a.nameLast), TRIM(a.nameFirst), TRIM(a.nameMiddle))
           WHERE a.lastFirstMiddle = 0;
    The only common data is the LastFirstMiddle name but each table has the field(s) in a different format and I can't figure out how to match them.

    I have 2 tables which contain name information.

    Table A contains varchar fields LastName, FirstName and MiddleName, i.e "Public", "John", "Q".

    Table B contains the name all in one field TRIMedName, i.e., "PublicJohnQ".

    I'd like to update Table A with the TRIMedName field.
    .
    I was thinking of something like comparing each of the separate name fields against the TRIMedName field in the WHERE clause:
    LastName LIKE TRIMedName AND
    FirstName LIKE TRIMedName AND
    MiddleName LIKE TRIMedName.

    I need a way to see if the field is contained in the TRIMed field in the WHERE clause.

    LIKE doesn't work; CONCAT isn't appropriate and I haven't figured a way to use SUBSTRING, any one have any pointers?

    Thanks,

    John
    Last edited by jbrasher; Oct 6, 2009 at 14:25. Reason: I'm dumb :-)

  2. #2
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should really have a unique ID # for each person. What you are trying to do is prone to being buggy.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jbrasher View Post
    LIKE doesn't work
    not the way you're using it, no

    have you tried using wildcards?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    eruna,

    I know but I'm playing with some excel data and build my tables and I'm new to DB design.

    r937,

    I'm a long time follower of your advice and I have bought your book, I guess I'll have to read it now :-)

    Really, the problem is that I'm trying to compare 2 fields from 2 different tables to get a match and not a sting. I think I've gone beyond what SQL was meant to do and I'll have to do some PHP.

    Thanks,

    John


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
  •