Query help

Dear All,
I have table called tblTransaction. I have my query such as this
“SELECT * FROM tbltransaction WHERE productID=2715 AND (outletFromID=4 OR outletToID=4) ORDER BY transactionDate,transactionTime,transactionDetailsID”. The problem now I want to know is that if outletFromID!=4 and (transactionType=‘ti’). So if it not from outletFromID=4 then I just want to look for transactionType=‘ti’. How can I do this? Thank you.

Dear Guido,
Thank you it works just addition I had to add was (outletFromID=4 and transactionType<>‘ti’).


SELECT * 
FROM tbltransaction 
WHERE productID = 2715 
AND (outletFromID = 4 OR 
     (outletToID = 4 AND transactionType = 'ti')
    ) 
ORDER BY 
    transactionDate
  , transactionTime
  , transactionDetailsID

Dear Guido,
Ok my current query gives me all the transaction which have either outletFromID=4 or outletToID=4. The extra thing I want is that if it is outletToID=4 then the transactionType must be only ‘ti’ and no others. I hope I am clearer now.

Please post your query inside the appropriate tags.
And I’m not sure if you want a new query with those two criteria, or if you want to add them to the existing query. I’ll go for the first :slight_smile:


SELECT * 
FROM tbltransaction 
WHERE outletFromID <> 4 
AND   transactionType = 'ti'
ORDER BY 
    transactionDate
  , transactionTime
  , transactionDetailsID