Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > Help in query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-28-08, 10:42
hYph3n hYph3n is offline
Registered User
 
Join Date: Jul 2006
Posts: 23
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 ?
Reply With Quote
  #2 (permalink)  
Old 05-28-08, 10:59
m42 m42 is offline
Registered User
 
Join Date: Apr 2008
Posts: 28
Yes, i have
Reply With Quote
  #3 (permalink)  
Old 05-28-08, 11:19
mike_bike_kite mike_bike_kite is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 944
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
Reply With Quote
  #4 (permalink)  
Old 05-28-08, 18:55
hYph3n hYph3n is offline
Registered User
 
Join Date: Jul 2006
Posts: 23
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.
Reply With Quote
  #5 (permalink)  
Old 05-29-08, 04:06
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,131
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
You only stop learning when you stop asking questions.
Reply With Quote
  #6 (permalink)  
Old 05-29-08, 05:09
mike_bike_kite mike_bike_kite is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 944
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
Reply With Quote
  #7 (permalink)  
Old 05-29-08, 10:51
hYph3n hYph3n is offline
Registered User
 
Join Date: Jul 2006
Posts: 23
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On