SQL Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajitk
    New Member
    • Feb 2008
    • 77

    SQL Query

    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
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Use JOIN to "join" the two tables.

    Happy coding

    ---- CK

    Comment

    • sajitk
      New Member
      • Feb 2008
      • 77

      #3
      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....wu d be grateful if the you could help me in writing the SQL.

      Thanks / Sajit



      Originally posted by ck9663
      Use JOIN to "join" the two tables.

      Happy coding

      ---- CK

      Comment

      • jackthomas
        New Member
        • Jul 2009
        • 3

        #4
        Improving the initial speed of a 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>
        Last edited by Frinavale; Jul 30 '09, 01:49 PM. Reason: Removed link. Please do not post any links that are not relevant to helping solve the problem at hand.

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

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

          Happy Coding!!!


          --- CK

          Comment

          • sajitk
            New Member
            • Feb 2008
            • 77

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

            Comment

            • MrMancunian
              Recognized Expert Contributor
              • Jul 2008
              • 569

              #7
              Originally posted by sajitk
              Can somebody explain me with the code......pls.. .i am running out of time.
              I don't see code to explain...

              Steven

              Comment

              Working...