Thursday, May 2, 2013

The last vestige of me thinking in imperative manner

SQL is a declarative language, but there are some imperative code lurking in an SQL query. Case in point:

select d.*, p.product_name
from order_detail d
join product p on p.product_id = d.product_id

Did you spot the imperative code there?

I still think of the second table and first table in terms of inner loop being compared to an outer loop, hence p.product_id = d.product_id. I should forget how things work under-the-hood, forget the loops, and be comfortable with a more declarative-looking code: d.product_id = p.product_id

No comments:

Post a Comment