Skip to main content


Showing posts from September, 2015

SQL: Selecting Values from a table with multiple initial values

The easiest way to explain this is by providing an example. Lets say that you have a table within the database called wheels. Lets say that you want to be able to provide the long description to a customer after he or she clicks on the particular wheel to view details, the abbreviated description to the warehouse and sales staff (to look it up on the boxes) and the short version to the customer when he or she is initially searching for the wheels; you don't want the customer to have 500 options for chrome (i.e. Chrome w/ Black Inserts, Chrome w/ Black Inlay, etc).

So you decide to store the finishes in a separate table called wheel_finish. The issue arises when you're selecting the item from the table. You can't execute the statement by calling an sql command like the one stored in $wrong_sql. Instead, you have to do a select statement for each individual finish within the main select statement. Here's an example: