Results 1 to 7 of 7

Thread: Help in query

  1. #1
    Join Date
    Jul 2006
    Posts
    26

    Unanswered: Help in query

    I have 2 tables.

    Table 1 have few fields and including (email, firstName, lastName, etc ... )

    Table 2 have few fields and including (email, name).

    I want to write a query which selects all data from table 1 and insert id, email, name (concat firstname + lastname) and insert it in table 2 appropriate columns.

    any idea ?

  2. #2
    Join Date
    Apr 2008
    Posts
    29
    Yes, i have

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    If you attach the original assignment and supply your teacher's email address we should be able to improve the turnaround speed of your homework and get fewer errors.

    Mike

  4. #4
    Join Date
    Jul 2006
    Posts
    26
    Quote Originally Posted by mike_bike_kite
    If you attach the original assignment and supply your teacher's email address we should be able to improve the turnaround speed of your homework and get fewer errors.

    Mike

    lolz .. well it's not an ASSIGNMENT. i am really working on some project and it's been quite a long that i have done any DB thingy. since most of the time i was working on C/C++/Delphi (creating system level things) and now after long time i have been moved to JAVA (Enterprise Application). so .. that's why i am seeking help from you people, if you people do.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Is there any reason why you want to concatenate first and last names into a single field? Take my word for it when I tell you that you'll be wanting to split them back up again real soon
    George
    Home | Blog

  6. #6
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Must admit I can't see why you want to duplicate data that you have stored in one table into another table but if you have a good reason to then simply write the select statement that will return all the field values that you want to insert into the new table. To create a unique id you'll need to investigate auto_increment fields. Finally turn the select statement into an insert statement.

    Seeing as you've been using MySQL for over 2 years now it may well be worth investing in a cheap book on MySQL and doing a little reading

    Mike

  7. #7
    Join Date
    Jul 2006
    Posts
    26
    ok guys thanks for the help. i successfully wrote the query that i was looking for. i am writing here so that if someone is seeking help for such kinda query - then this post might help him

    Code:
    insert into user_activity (node_id, email, name) 
    	select node_id, email, concat(first_name, ' ', last_name) as name from node

Posting Permissions

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