Need guidance

Discussion in 'PHP' started by JScripting, Aug 10, 2008.

  1. #1
    Its not usual for me to be asking for help but this script im trying to do is VERY complicated.

    Here is my situation:

    Table 1
    ------------
    ID ONE TWO
    ------------
    1 A 9
    2 B 4
    3 C 12
    4 D 2

    Table 2
    -----------
    ID LID TXT
    -----------
    1 3 AB
    2 2 CD
    3 1 LA
    4 4 PQ

    Usually I would select the data like so from table 2:
    4 4
    3 1
    2 2
    1 3

    ID DESC, you see.

    But in this case, LID refers to an ID in Table 1.
    I want to select data from Table 2, ordered by ID AND "TWO" in Table 1.

    Something like:
    ORDER BY id DESC, table1.two DESC

    If I did a proper query using the same logic as the example above, the data would be ordered by id as expected but then when ordered by "TWO", it would totally unorganise it all and put OLD ID's at the top.

    What I need to do is select data from Table 1 ordered by ID and ordered by TWO in Table 1 while keeping importance on Table 1's ID DESC.

    I hope you see what I mean, any help will be appreciated.
     
    JScripting, Aug 10, 2008 IP
  2. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #2
    I'm not 100% sure this is right but it's a start atleast:

    "SELECT table1.id, table1.two, table2.id, table2.lid, table2.txt 
    FROM table2
    INNER JOIN table2 ON table2.lid = table1.two
    ORDER BY id DESC, table1.two DESC"
    PHP:
     
    Silver89, Aug 13, 2008 IP