By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,766 Members | 1,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,766 IT Pros & Developers. It's quick & easy.

SQL Query

P: 77
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
Jul 28 '09 #1
Share this Question
Share on Google+
6 Replies


ck9663
Expert 2.5K+
P: 2,878
Use JOIN to "join" the two tables.

Happy coding

---- CK
Jul 28 '09 #2

P: 77
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



@ck9663
Jul 28 '09 #3

P: 3
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>
Jul 28 '09 #4

ck9663
Expert 2.5K+
P: 2,878
I have not created a sample for it, but you might want to explore Common Table Expression

Happy Coding!!!


--- CK
Jul 29 '09 #5

P: 77
Can somebody explain me with the code......pls...i am running out of time.
Jul 29 '09 #6

MrMancunian
Expert 100+
P: 569
@sajitk
I don't see code to explain...

Steven
Aug 4 '09 #7

Post your reply

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