Solved

MySQL Select Insert with a constant field

Posted on 2008-06-22
2
1,877 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
Comment Utility
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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now