?
Solved

How to insert a inner join query in a table

Posted on 2012-08-21
5
Medium Priority
?
544 Views
Last Modified: 2012-08-21
Hi

I have this query:

SELECT tbhy_logdata_20120821.User, tbhy_logdata_20120821.UserName, tbhy_logdata_20120821.Desk, tbhy_logdata_20120821.Action, tbhy_logdata_20120821.Field, CONCAT(tbhy_logdata_20120821.Project,'<|1|>',tbhy_logdata_20120821.Desk,'<|1|>',tbhy_logdata_20120821.Action,'<|1|>',tbhy_logdata_20120821.Field) AS CON, tbasys_timeline_a.TimeLine, tbasys_timeline_a.Concatenate FROM tbhy_logdata_20120821 INNER JOIN tbasys_timeline_a ON Concat(tbhy_logdata_20120821.Project,'<|1|>',tbhy_logdata_20120821.Desk,'<|1|>',tbhy_logdata_20120821.Action,'<|1|>',tbhy_logdata_20120821.Field) =tbasys_timeline_a.Concatenate

And I have to insert this into a table that has 7 fields: User, UserName, Desk, Action, Field, Concat, TimeLine!

Thank you,
0
Comment
Question by:Qw M
  • 2
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38315290
simply do a INSERT:;

insert into yourtable ( User, UserName, Desk, Action, Field, Concat, TimeLine )

SELECT tbhy_logdata_20120821.User, tbhy_logdata_20120821.UserName, tbhy_logdata_20120821.Desk, tbhy_logdata_20120821.Action, tbhy_logdata_20120821.Field, CONCAT(tbhy_logdata_20120821.Project,'<|1|>',tbhy_logdata_20120821.Desk,'<|1|>',tbhy_logdata_20120821.Action,'<|1|>',tbhy_logdata_20120821.Field) AS CON, tbasys_timeline_a.TimeLine, tbasys_timeline_a.Concatenate FROM tbhy_logdata_20120821 INNER JOIN tbasys_timeline_a ON Concat(tbhy_logdata_20120821.Project,'<|1|>',tbhy_logdata_20120821.Desk,'<|1|>',tbhy_logdata_20120821.Action,'<|1|>',tbhy_logdata_20120821.Field) =tbasys_timeline_a.Concatenate

Open in new window

0
 
LVL 12

Expert Comment

by:Anuradha Goli
ID: 38315304
Insert into <newtable>(<field1>,<field2>,.............,<field7>)
(
select statement.....................
);

Open in new window

0
 

Author Comment

by:Qw M
ID: 38315312
@angelIII: I get an error: Column count dosen't match value count at row 1!

Thank you,
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38315328
well, your SELECT indeed returns 8 columns, so you need to remove the one you don't want be inserted to the final table
0
 

Author Comment

by:Qw M
ID: 38315329
@angelIII: Got it! I missed 1 column.

Thank you for your support!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

809 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