Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables like following:
Table one is named KLASA which has following two columns:
here is primary key (ID_Klasa) and (KlasaViti)
Table two is maed PARALELJA which has following three columns:
primary key (ID_Paralelja) (Paralelja) and (ID_Klasa).
What I'm pretending to do is to make a query to get the combination of KlasaViti from first table and Paralelja from second table. The result of that I want to insert into table two.
for example table one has ID_Klasa=3 , KlasaViti=2, table two has ID_Paralelja=3, Paralelja=1. I want to automatically find the combination of Klasa=2 and Paralelja=3 and to get the ID_Klasa from table one, that value I want to insert at the ID_klasa at the table two.

I'm little bit confused how to do that.
Here is some code what I'm trying but I'm having no result:

SQL
SELECT k.ID_Klasa FROM [Projekti_TI_1].[dbo].[KLASA] AS k
 JOIN [Projekti_TI_1] .[dbo].[PARALELJA]  as p on
 k.KlasaViti = p.Paralelja
 where k.ID_Klasa = p.ID_Klasa


Thank you in advance for taking time reading this request.
Cheers.

EDIT:
Probably I did not made my request properly. I think that following picture shows you my problem.
<img src="http://i444.photobucket.com/albums/qq165/dr_iton/SQLstatement_zps6d18d49f.jpg" border="0" alt=" photo SQLstatement_zps6d18d49f.jpg"/>
Posted
Updated 29-Jan-14 21:32pm
v2

I solved by myself using stored procedure I've got the value and stored in local value, after that I used that value and sent to the proper column in Table 2.
Once again thank you for your help.
 
Share this answer
 
If you perform Inner join on two tables, Automatically it will match the particular column on both the tables.

SQL
SELECT k.ID_Klasa FROM [Projekti_TI_1].[dbo].[KLASA] AS k
 JOIN [Projekti_TI_1] .[dbo].[PARALELJA]  as p on
 k.KlasaViti = p.Paralelja
 where k.ID_Klasa = p.ID_Klasa
 
Share this answer
 
Comments
dr_iton 30-Jan-14 12:38pm    
Take a look at my post I edited the question. So all I want is when I select a specific combination of rows from first table and second table to get the ID_Klasa and to automatically insert that in third column.
Or to be more specific. How to get ID_Klasa from table KLASA and insert that value in ID_Klasa at table PARALELJA.
Karthik_Mahalingam 30-Jan-14 12:40pm    
ok i wil check
Karthik_Mahalingam 30-Jan-14 12:42pm    
ID_Klasa in pralaeja table is forigen key ?
dr_iton 30-Jan-14 18:02pm    
yes ID_Klasa in table PARALELJA is a foreign key, so I'm creating a stored procedure and have two textboxes, in one textbox I input data for KlasaViti in table KLASA and in second textbox I input data for Paralelja in Table PARALELJA. What I intend to do is Input those data in both tables, and as you can see ID_Klasa in table KLASA and ID_Paralelja in Table PARALELJA are auto increment values. My problem is how to get ID_Klasa value form table KLASA and that value to store in column ID_klasa at PARALELJA table.
Karthik_Mahalingam 30-Jan-14 18:04pm    
noramally, when v are inserting a value in the primary key table, we will update the forigen key table with the key.. using identity value..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900