Connecting Tech Pros Worldwide Help | Site Map

SQL Query

Member
 
Join Date: Feb 2008
Posts: 75
#1: Jul 28 '09
Hi,

I have 2 tables namely Cont_Dtls and Node_Dtls

The structure of Cont_Dtls is as follows:

Cont_ID FName Address
BCF01 Sajit XYZ
BCF02 ABC MNO
BCF03 EFG XXX

The structure of Node_Dtls is as follows

Cont_ID Node_ID Parent_ID
BCF01 52 50
BCF02 53 52
BCF03 54 51

So what is want from an SQL is if the user selects the Node_ID = 52 the corresponding Cont_ID details would be displayed. Now, if the same Node_ID is present in the Parent_ID then the details of that record would also be displayed. So this query should display the records of BCF01 and BCF02.

Hope i am able to explain it properly...help would be highly appreciated.

Thanking you all in advance
Sajit
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Jul 28 '09

re: SQL Query


Use JOIN to "join" the two tables.

Happy coding

---- CK
Member
 
Join Date: Feb 2008
Posts: 75
#3: Jul 28 '09

re: SQL Query


Sorry CK,

Actually the opposite is happening..i will just explain the whole thing again....

Cont_ID FName Address
BCF01 Sajit XYZ
BCF02 ABC MNO
BCF03 EFG XXX
BCF04 sdd dddd
BCF05 DDD WWW

The structure of Node_Dtls is as follows

Cont_ID Node_ID Parent_ID
BCF01 52 50
BCF02 53 52
BCF03 54 51
BCF04 56 53
BCF05 57 56

So what i want from an SQL is, if the user selects the Parent_ID = 52 then the corresponding Cont_ID details would be displayed. in this case the CONT_ID BCF02 is displayed. Now, if the same Node_ID (i.e 53) is present in the Parent_ID then the details of that record would also be displayed. So this query should display the records of BCF02, BCF04, BCF05. The search will stop here because the Node_ID (57) is not present in the Parent_ID.

Sorry for the confusion....wud be grateful if the you could help me in writing the SQL.

Thanks / Sajit



Quote:

Originally Posted by ck9663 View Post

Use JOIN to "join" the two tables.

Happy coding

---- CK

Newbie
 
Join Date: Jul 2009
Posts: 3
#4: Jul 28 '09

re: SQL Query


I have optimized my SQL query to the maximum extent.

The first time I ran the query, it took 7 seconds; the next time it took half a second.

Why did this happen? How can I make the query run faster the first time around?


<link removed>
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#5: Jul 29 '09

re: SQL Query


I have not created a sample for it, but you might want to explore Common Table Expression

Happy Coding!!!


--- CK
Member
 
Join Date: Feb 2008
Posts: 75
#6: Jul 29 '09

re: SQL Query


Can somebody explain me with the code......pls...i am running out of time.
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 274
#7: Aug 4 '09

re: SQL Query


Quote:

Originally Posted by sajitk View Post

Can somebody explain me with the code......pls...i am running out of time.

I don't see code to explain...

Steven
Reply


Similar Microsoft SQL Server bytes