ePrivacy and GPDR Cookie Consent by Cookie Consent

Taking care with your select projections can speed up your retrievals. In other words, don't select fields you don't need.

The select projection using the wildcard (*)

Using the wildcard guarantees all columns from the selected tables will be returned. Few problems here:

  • If you're joining to different tables there may be replicated column names in the results.
  • It's unusual to require every single field in any given situation, so any extra fields returned is just an overhead both for sql and if you're passing more data than required back up to the application.
  • It's a lazy development style. Specifying fields refreshes your mind and makes you think about the schema and ways to mature it.
-- using the wild card in a select statement
select *-- * symbol here means return all columns, a wildcard
from tblWidgets-- table we want to retrieve from
                            
The targeted select projection

This time we specify that only the fields we want are returned, in this case the field is widget_name

-- using a targeted select statement
select tw.widget_name-- targeted select statement just retrieving the field widget_name
from tblWidgets tw-- table we want to retrieve from, using table a label tw
                            


#SQL techniques#SQL

Want to get started?

Contact James on 01244 722 302
Chester, Cheshire, U.K.

--