Example table for MySQL
In my MySQL posts I've tended to use fruit in my example tables, so in this post will standardize the table structure and data that appears in future examples. Those future posts will refer back to this post for the table structure and base data.
Table schema
Use this to create the table schema:
I realise that this should really be normalised with two tables, one for the fruit and another for the varieties, but this simplistic non-normalised table is going to be useful for simple examples presented in future posts.
Table data
Use the following SQL to insert the data. I've mixed up the order of the names and varieties so when doing a query without ORDER BY they come out in a random order.
SELECT * FROM fruit
This is the output from SELECT * FROM fruit:
Note that although the data is in order of the fruit_id, after doing some deletes and inserts (or truncates and re-inserting the data) it could be in any order. You can never count on the order of data from a SQL query unless ORDER BY is used.
Posts with this example
Refer to the "related posts" links below for posts using this example table. The first one will be posted this time next week, looking at how to order in a particular order that is different from the way ORDER BY would normally order it.
0 comments:
Post a Comment