Category Archives: SQL Tips n Tricks

Calculate the Running Balance

How to calculate the running balance on a ledger using self-joins.
Posted in SQL Tips n Tricks | Tagged , , , , | Leave a comment

Find user’s most recent post in each thread

One common problem that my sequence method can help to solve is how to display the most recent entry that a user has made in each thread that the user has contributed to: SELECT * FROM posts WHERE usedid = $userid AND postid IN (SELECT t1.postid, COUNT(t1.postid) AS sequence, t1.postid <= t2.postid AS flg FROM [...]
Posted in SQL Tips n Tricks | Tagged , , , , | 1 Comment

How to Sequence each Sub-set of Records

How to find/display/keep/delete the first/last n posts/records/entries for each user by using a sequence.
Posted in SQL Tips n Tricks | Tagged , , , , | 2 Comments