MySQL SELECT

The SELECT statement is used to fetch data from a database. The data returned is stored in a result table, called the result set.

Example with Tamil Kings

1. Selecting All Columns

SELECT * FROM tamil_kings_auto_increment;

Code Explanation: This query selects all columns from the tamil_kings_auto_increment table.

2. Selecting Specific Columns

SELECT king_name, reign_period FROM tamil_kings_auto_increment;

Code Explanation: This query selects only the king_name and reign_period columns from the tamil_kings_auto_increment table.

Best Practices

  • Use SELECT * only when you need all columns; otherwise, specify the columns to improve performance.
  • Consider using aliases to make query results more readable.

Key Takeaways

  • The SELECT statement is used to retrieve data from one or more tables.
  • Specify column names to retrieve only the necessary data.