I am checking if an item has a linked item in the database but cant decide where to put the condition.
option one: place the condition in the database read statement.
select * from item where id = id.
Option two check afterwards in code.
temp = select * from item
for(i = 0; i <sizeof(temp); i++;
{
if(id = temp.id)
{do stuff}
}
Is there a significant difference between the two ?
note code sample probably contains tons of errors, is for explanation purpose only.
Yes. In the first, you’re asking the database for a smaller result set, which may require less effort by the database, less network traffic, and less work by your code.
With the second, you’re asking to be featured on thedailywtf.