patternsqlMinor
Finding the runtime of a task by name
Viewed 0 times
theruntimenamefindingtask
Problem
Can this query be improved? I iterate over a couple of thousand times, and if I can improve it, it should decrease the run time. Otherwise I might look into using a batch instead of doing one at a time. I'm using MS SQL 11.
job
****
id
name
job_stats
*************
id
job_id
median_runtime
select js.median_runtime from job_stats js
join job j
on j.id = js.job_id
where j.name = '%s'Solution
With a query this simple, it's going to be hard to make any major improvements.
Firstly, you should use
I would argue that you don't need to alias
You should use consistent indentation and you SQL is typically written with all the keywords in uppercase like this:
Lastly, is the final statement supposed to be this:
or is it correct as is, I can not tell.
Firstly, you should use
INNER JOIN as opposed to JOIN it makes the query much easier to understand at a glance.I would argue that you don't need to alias
job_stats or job, they are both already fairly short and are much more meaningful names than J and JS You should use consistent indentation and you SQL is typically written with all the keywords in uppercase like this:
SELECT job_stats.median_runtime
FROM job_stats
INNER JOIN job
ON job.id = job_stats.id
WHERE job.name = '%s'Lastly, is the final statement supposed to be this:
WHERE job.name LIKE '%s'or is it correct as is, I can not tell.
Code Snippets
SELECT job_stats.median_runtime
FROM job_stats
INNER JOIN job
ON job.id = job_stats.id
WHERE job.name = '%s'WHERE job.name LIKE '%s'Context
StackExchange Code Review Q#64296, answer score: 4
Revisions (0)
No revisions yet.