x
login about faq Site discussion (meta-askssc)

to ask a question on join using insert statement

hello suppose my table name is xyz in which three columns are there and another table abc also consist of three column, having id column common n both of them.normally we have seen that joins are used using select statement but i dont wana select column using join. i wana insert column using joins.i want to make use of insert statement in join not select. plz anyone answer ma question.

more ▼

asked Feb 03 '10 at 03:42 PM in Default

java gravatar image

java
9 3 4 4

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

I'm not 100% sure what you are trying to do, but I hope this helps.

INSERT INTO jki
    (id)
    SELECT abc.id
    FROM abc
    	INNER JOIN xyz
    		ON xyz.id = abc.id

It will insert into table jki any id values that are found in both abc and xyz.

Another method that might work better for you in some situations is to use WHERE EXISTS:

INSERT INTO jki
    (id)
    SELECT abc.id
    FROM abc
    WHERE EXISTS
    	(SELECT * FROM xyz WHERE xyz.id = abc.id)
more ▼

answered Feb 03 '10 at 03:58 PM

Tom Staab gravatar image

Tom Staab
5.8k 5 8 10

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x100
x91

asked: Feb 03 '10 at 03:42 PM

Seen: 522 times

Last Updated: Feb 03 '10 at 04:00 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.