SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Query help

  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    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
    Code MySQL:
    SELECT * 
    FROM tbltransaction 
    WHERE outletFromID <> 4 
    AND   transactionType = 'ti'
    ORDER BY 
        transactionDate
      , transactionTime
      , transactionDetailsID

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code MySQL:
    SELECT * 
    FROM tbltransaction 
    WHERE productID = 2715 
    AND (outletFromID = 4 OR 
         (outletToID = 4 AND transactionType = 'ti')
        ) 
    ORDER BY 
        transactionDate
      , transactionTime
      , transactionDetailsID

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Guido,
    Thank you it works just addition I had to add was (outletFromID=4 and transactionType<>'ti').


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
  •