473,473 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SubSelects to JOINS

45 New Member
Hi all,

I am trying to write a SQL Querry that inserts rows into a table by selecting values from another tables.

General Syntax for inserting values into a table from one or more tables is as follows

INSERT INTO <table_name> | <view_name> [ ( <column_list> ) ] SELECT <column_list>
| <literal_value> FROM <table_name> | <view_name>

My querry looks something like this...

INSERT INTO <table_name> [ ( <column1, column2, column3, ...> ) ]
SELECT <column1, column2, (SELECT <column1> FROM <table_name> )>
FROM <table_name>

this works for me...

But my question is ... Can I use joins instead of these SubSelects?

If yes, please provide me with some ex code.

Many thanks.
May 3 '07 #1
2 1826
brutusram
5 New Member
Do you need to insert multiple table information into this table? If you do then the inner join can be used in the Insert statement like this below:

Expand|Select|Wrap|Line Numbers
  1. INSERT 
  2. INTO tbl_InsertMe 
  3. (myCol1, myCol2, yourCol1, yourCol2)
  4. SELECT 
  5. tbl1.myCol1,
  6. tbl1.myCol2,
  7. tbl2.yourCol1,
  8. tbl2.yourCol2
  9. FROM
  10. tbl1
  11. INNER JOIN
  12. tbl2
  13. ON
  14. tbl1.PrimaryKey=tbl2.ForeignKey
  15. ---You can place your where statement here if you need one.
  16.  
I tried to make that clear. If you need anymore help with this let me know.

BrutusRam

Hi all,

I am trying to write a SQL Querry that inserts rows into a table by selecting values from another tables.

General Syntax for inserting values into a table from one or more tables is as follows

INSERT INTO <table_name> | <view_name> [ ( <column_list> ) ] SELECT <column_list>
| <literal_value> FROM <table_name> | <view_name>

My querry looks something like this...

INSERT INTO <table_name> [ ( <column1, column2, column3, ...> ) ]
SELECT <column1, column2, (SELECT <column1> FROM <table_name> )>
FROM <table_name>

this works for me...

But my question is ... Can I use joins instead of these SubSelects?

If yes, please provide me with some ex code.

Many thanks.
May 4 '07 #2
querry
45 New Member
Its a bit late, but thank you very much.
May 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Petre Agenbag | last post by:
Hi List Can anyone help me to do the following without the need of subselects: I have a table that contains rows where mostly, the only common field is the "name". The rest of the data...
0
by: Jacob Friis Larsen | last post by:
Which is fastest? This: SELECT id, title FROM questions LEFT JOIN users USING (userid) WHERE zipcode = 2000; or this: SELECT id, title FROM questions WHERE userid IN (SELECT userid FROM...
6
by: J Smith | last post by:
After doing some googling through the lists and such, I wasn't able to arrive at a solution for a problem I've run into recently. I've seen mention of similar symptoms, but my case seems different....
6
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid,...
0
by: Hegedus, Tamas . | last post by:
Dear All, I am a biologist and I do not know what to expect from an RDB (PgSQL). I have large tables: 1215607 rows in prots, 2184596 rows in kwx (see table details below). I would like to do...
1
by: Mike Mascari | last post by:
This is a really trivial question, but I'm curious. Why do subselects in target lists behave differently than simple queries? Ex: create temporary table bar (key varchar(32) not null);...
0
by: Tarun Mistry | last post by:
Hi guys, I have posted this in 2 groups hoping to catch up on some difference knowledge. I am making an application in c# with a SQL 2000 back end. I am trying to use the new dataset available...
1
by: nullGumby | last post by:
I'm trying to get a UNION of UserIDs from multiple subselects. The original query--which puts all the found UserIDs into separate columns, looks like this: ...
36
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.