Get startedGet started for free

Selecting fields

1. Selecting fields

Remember that impressive query we saw at the start of the first video? It started with the same fundamental command we're using: SELECT.

2. The SELECT statement

Our queries contain two commands: SELECT tells the database what to show, and FROM, tells it where to look. Together, they form a complete SQL query, and the returned records are called the result set.

3. Selecting a specific field

When we asked the AI assistant, "What are the product names?", it understood that we only needed the product name field from the products table because we've set it up with knowledge of our PoweredHomes database.

4. Selecting a specific field

Without this setup, we'd need more specific prompts like "Show the product_name field from the products table". Looking at one field gives us a cleaner, more focused view of our data.

5. Selecting all fields

However, sometimes we need to inspect everything in a table. A prompt asking for all product information might be "Show me everything from the products table", though many variations would work. The AI assistant may generate different SQL code from the same prompt, so we need to apply our SQL and database knowledge to check the result. A prompt asking to see everything could generate a SQL query that lists all of the fields within the SELECT statement. Since we've reviewed the tables in our database, we know this list is correct.

6. Selecting all fields

Or it might instead use an asterisk in the SELECT statement. The asterisk is SQL's shortcut for "select all". It's known as a wildcard. Here, the AI assistant chose the fastest path to the answer, and we can verify it's another correct approach. Whether we list field names or the wildcard depends on our goal. Listing field names improves readability when sharing code, but the wildcard shortcut is ideal for quick exploration.

7. Selecting multiple fields

If we want to see multiple fields but not all, we can try asking: "Show the name and category for each product". The key is being specific about which fields we want to see.

8. Data exploration

Early on, it's wise to query some or all fields to familiarize ourselves with the data. This helps us understand what data is available, making it easier to verify results and decide what questions to ask. This exploration approach is exactly how data professionals work! We explore first to understand the data, making analysis and communication easier. Without this exploration, we may end up asking a question that is not answerable with our data. AI accelerates this workflow, but it still relies on our judgment to decide what to ask and whether the answers make sense.

9. Let's practice!

You now have the essentials for exploring any table with AI. Let's practice with a few more prompts to explore the fields and tables in our database.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.