If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 09:42
hYph3n hYph3n is offline
Registered User
 
Join Date: Jul 2006
Posts: 26
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, 09:59
m42 m42 is offline
Registered User
 
Join Date: Apr 2008
Posts: 29
Yes, i have
Reply With Quote
  #3 (permalink)  
Old 05-28-08, 10:19
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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, 17:55
hYph3n hYph3n is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 05-29-08, 03:06
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
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
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 05-29-08, 04:09
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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, 09:51
hYph3n hYph3n is offline
Registered User
 
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
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

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