SQL Query Query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Hall

    #1

    SQL Query Query

    Hello,

    I am having a problem writing an SQL query.

    The tables I have are

    History

    id transaction_id state_id
    1 1 1
    2 1 2
    3 1 3
    4 1 5
    5 2 1
    6 2 2
    7 2 3
    8 2 4

    And

    Transactions

    id
    1
    2

    I want to be able to return a result that provides me only with the
    transaction_id' s that do not contain a tuple in history where they have a
    state_id of 4. So for example in the table above I would only want
    transaction_id 1.

    Thank you very much for any help and pointers you can give me

    Cheers Chris


  • Aggro

    #2
    Re: SQL Query Query

    Chris Hall wrote:
    [color=blue]
    > I want to be able to return a result that provides me only with the
    > transaction_id' s that do not contain a tuple in history where they have a
    > state_id of 4. So for example in the table above I would only want
    > transaction_id 1.[/color]

    select Transactions.id from Transactions
    left join History on History.transac tion_id=Transac tions.id
    and History.state_i d=4
    where History.transac tion_id is null;

    Comment

    Working...