Navigation

Portable SQL : Statements : Data retrieval : Simple SELECT

From Linuxnetworks

The simplest SELECT statement for fetching records from a single table which is supported by all database engines is

SELECT column-list
FROM table
WHERE conditions

To be on the save side column-list should be either a comma-separated list of column names or an asterisk (*). The asterisk symbol frees you from the burden to list all columns you would like to access in your application. But be careful! If your table has many columns the performance drops significant because more values have to be passed to the client over the network and the wire is the bottleneck most of the time. The problem will get worse if the table contains columns with much data for the same reason. Moreover, additional problems may arise as soon as you begin to join another table so don't use the asterisk without thinking twice if it's worth the potential trouble!

Keep an eye on the conditions list as using uncommon operators or built-in functions provided by the database engine tend to decrease the portability of statements. If your table contains user generated content it's also important to use sane conditions to minimize the amount of records sent by the database server. Otherwise, you will face the same problem as above.