Querying Data
The VMart database installs with sample scripts that contain SQL commands that represent queries that might be used in a real business. Use basic SQL commands to query the database, or try out the following command. Once you’re comfortable running the example queries, you might want to write your own.
Note: The data that your queries return might differ from the example output shown in this guide because the sample data generator is random.
Type the following SQL command to return the values for five products with the lowest fat content in the Dairy department. The command selects the fat content from Dairy department products in the product_dimention
table in the public
schema, orders them from low to high and limits the output to the first five (the five lowest fat contents).
VMart => SELECT fat_content FROM ( SELECT DISTINCT fat_content FROM product_dimension WHERE department_description IN ('Dairy') ) AS food ORDER BY fat_content LIMIT 5;
Your results will be similar to the following:
fat_content ------------- 80 81 82 83 84 (5 rows)
The preceding example is from the vmart_query_01.sql
file. You can execute more sample queries using the scripts that installed with the VMart database or write your own. For a list of the sample queries supplied with Vertica, see the Appendix.