Welcome to WebmasterWorld Guest from 107.20.54.98

Forum Moderators: open

Message Too Old, No Replies

How to query Sub-queries in same table.

     
7:38 pm on Apr 17, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 20, 2006
posts:109
votes: 0


can i do this?

SELECT * FROM transactions as t1 WHERE TotalAmount < (SELECT SUM(t2.TotalAmount) FROM transactions as t2 WHERE t1.TransactID = t2.TransactRefID) ORDER BY ActualDate DESC;

does it work? as i tested, no error.. but no result to.. all i know, it should have a results...

8:45 am on Apr 18, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 20, 2006
posts:109
votes: 0


can anybody answer me please? please help..

thanks..

10:28 am on Apr 19, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:July 19, 2004
posts:136
votes: 0


First of all you dont need to add t1,t2. We name the tables as t1,t2....if there are more then 1 table.
try removing t1 and t2 and then fire the query.

SELECT * FROM transactions WHERE TotalAmount < (SELECT SUM(TotalAmount) FROM transactions WHERE TransactID = TransactRefID) ORDER BY ActualDate DESC

Let me know if it works or not