August 29, 2013

Execute query that normally runs on a single ID for every ID

Damien.Bell’s Question:

So I have this query:

SELECT     ABS(TIMESTAMPDIFF(MINUTE, NOW(), 
(SELECT    MAX(`Time`) 
FROM       ddHistorical 
WHERE      ID = '5')))

I want to run that on every ID in my database, how would I do that?

Just remove the WHERE part, it will run on every rows.

SELECT ABS(TIMESTAMPDIFF(MINUTE, NOW(), (SELECT MAX(`Time`) FROM ddHistorical

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!