Solved

MySQL Select Insert with a constant field

Posted on 2008-06-22
2
1,879 Views
Last Modified: 2008-08-17
I have an SQL querty which works great:-

insert into myTable select * from otherTable;

but what Id like to do is insert another column which is constant, so something like

insert into myTable `firstColumnValue' select * from other table.

Does this make sence?
0
Comment
Question by:tonelm54
2 Comments
 

Author Comment

by:tonelm54
ID: 21840601
So in the first query the result would inserts:-
Col1      Col2      Col3      Col4      Col5
--------------------------------------------------------------------------------------------------------------------------
value11      value12      value13      value14      value15
value21      value22      value23      value24      value25
value31      value32      value33      value34      value35
value41      value42      value43      value44      value45
value51      value52      value53      value54      value55
value61      value62      value63      value64      value65
value71      value72      value73      value74      value75

The second Id like to insert:-
Col1      Col2      Col3      Col4      Col5      Col6
--------------------------------------------------------------------------------------------------------------------------myConstValue      value11      value12      value13      value14      value15
myConstValue      value21      value22      value23      value24      value25
myConstValue      value31      value32      value33      value34      value35
myConstValue      value41      value42      value43      value44      value45
myConstValue      value51      value52      value53      value54      value55
myConstValue      value61      value62      value63      value64      value65
myConstValue      value71      value72      value73      value74      value75
0
 
LVL 3

Accepted Solution

by:
jagmohan_gunwant earned 500 total points
ID: 21840709
Hello Friend
For this Purpose of inserting a constant value in a column in another table you have to specify all the columns in the destination table and the constant column with the columns and source columns keeping in mind the field mapping which you have to connsider, threfore your insert query should be as follows:

Insert Into <DestinationTable> (Col1, Col2, COl3, Col4, Col5)
Select 'myConstValue' as Col1, Col2, Col3, Col4, Col5 
From <SourceTableName>

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
updating the date data 12 30
MySqlDump not dumping triggers 1 30
MySQL Error Code 2 19
INDEX does not make a difference, why? 10 46
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question