x

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, 2010 at 03:42 PM in Default

java gravatar image

java
9 4 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, 2010 at 03:58 PM

Tom Staab gravatar image

Tom Staab
5.8k 6 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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x123
x109

asked: Feb 03, 2010 at 03:42 PM

Seen: 960 times

Last Updated: Feb 03, 2010 at 04:00 PM