SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Help with query

  1. #1
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with query

    Hi,

    I am having following table in my database
    id no name prev_no action
    1 3 a 0 join
    2 3 a 0 confirm
    3 4 b 0 join
    4 3 a 0 transfer
    5 5 a 3 join
    6 4 b 0 confirm
    7 5 a 0 perform
    8 5 a 0 transfer
    9 4 b 0 perform
    10 7 a 5 join

    The output I want is
    id no name prev_no
    1 3 a 0
    5 5 a 3
    10 7 a 5

    Could anyone please help me for writing the query?

    Your help will be highly appriciated.

    Thanks,
    Barbara

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Why those 3 rows? What is the logic behind it?

  3. #3
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you look at the table no 3 has three 'join' action.

    for first join action, no is 3 and the prev_no is 0
    for second join action, no is 5 and prev_no is 3
    for second join action, no is 10 and prev_no is 5

    I can query using where clause (no = 10)

    Please help me.
    Barbara

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Ok, so if I understand correctly, you want all parents from a given child (starting from no 10, you want to get 5, 3, and 0).
    Take a look at this article of our sql expert r937: http://sqllessons.com/categories.html
    Please read it and try to understand it, then try to use the logic in your situation. If you are having difficulties, don't hesitate to ask.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •