+ Reply to Thread
Results 1 to 2 of 2

Thread: issue with select command

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    34

    issue with select command

    I have a table that saves the possible states of other tables (entities). But now I need to find equivalence of states between two entities. The table is like that :
    Code:
    ID   TableID   State        StateDefinition  StateDescription
    ================================================================
    1    1         1            Created          Just created
    2    1         2            Dropped          Just Dropped
    3    2         1            Created          Just Created
    4    2         2            Aproved          Passed the revision
    5    2         3            Dropped          Just dropped
    I want to get equivalent (comparing text of state) which as a result get this:
    Code:
       TableID1     StateValue1       TableID2       StateValue2    StateDefinition
    ======================================================================
       1            1                 2              1              Created
       1            2                 2              3              Dropped
    How can it done ?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    13
    Here is the solution :
    Code:
    select t1.TableID as TableID1,
        t1.State as StateValue1,
        t2.TableID as TableID2,
        t2.State as StateValue2,
        t1.StateDefinition  
    from MyTable t1
    inner join MyTable t2 on t1.TableID = 1 and t2.TableID = 2
    where t1.State = t2.State 
        and t1.StateDefinition  = t2.StateDefinition

+ Reply to Thread

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