Ever found yourself in need of inserting data into a SQL table? The SQL `INSERT INTO` statement is your go-to command, and understanding how to use it with `VALUES` is crucial. Let's dive into SQL `INSERT INTO VALUES` examples, making sure your database reflects the data you want it to hold.

Before we start, let's assume we have a simple `Students` table with columns `ID`, `FirstName`, `LastName`, and `Age`. Here's the table's basic structure:

```sql CREATE TABLE Students ( ID INT AUTO_INCREMENT, FirstName VARCHAR(50), LastName VARCHAR(50), Age INT, PRIMARY KEY(ID) ); ```
Inserting Single Row
Let's start by inserting a single row into our `Students` table. The `INSERT INTO` statement, followed by the table name (`Students`), columns (`FirstName`, `LastName`, `Age`), and the `VALUES` clause, looks like this:

```sql INSERT INTO Students (FirstName, LastName, Age) VALUES ('John', 'Doe', 20); ```
This SQL command will insert a new row with the first name 'John', last name 'Doe', and age 20 into the `Students` table.
Inserting with Literal Values

In the previous example, we used literal values. You can also use literal values when inserting data into your table, like this:
```sql INSERT INTO Students (FirstName, LastName, Age) VALUES ('Jane', 'Doe', 19); ```
This command will insert another row with the first name 'Jane', last name 'Doe', and age 19.
Inserting with Variable Values

Instead of using literal values, you can use variables to insert data into your table. Here's how you can do it using PHP and the MySQLi extension:
```php $fn = 'Jim'; $ln = 'Carrey'; $age = 60; $stmt = $conn->prepare("INSERT INTO Students (FirstName, LastName, Age) VALUES (?, ?, ?)"); $stmt->bind_param("ssi", $fn, $ln, $age); $stmt->execute(); ```
In this example, the variables `$fn`, `$ln`, and `$age` are passed to the prepared statement using the `bind_param` function and then inserted into the `Students` table.
Inserting Multiple Rows

To insert multiple rows, you can separate your values with commas in the `VALUES` clause, like this:
```sql INSERT INTO Students (FirstName, LastName, Age) VALUES ('John', 'Smith', 30), ('Emma', 'Stone', 32); ```
Using NULL Values



















You might need to insert a NULL value into your table. Here's how to do it:
```sql INSERT INTO Students (FirstName, LastName, Age) VALUES (NULL, 'Undecided', NULL); ```
In this case, the first name and age of the new student are unknown, so we insert NULL values for those columns.
Inserting and Selecting the Last ID
When you insert a new row with an `AUTO_INCREMENT` field (like `ID` in our `Students` table), you can use the `INSERT INTO ... SELECT` statement to get the last inserted ID. Here's how:
```sql INSERT INTO Students (FirstName, LastName, Age) VALUES ('Jessica', 'Alba', 40); SELECT LAST_INSERT_ID(); ```
The `LAST_INSERT_ID()` function will return the ID of the last row inserted, which can help you manage your data more effectively.
That's it! You've now seen various examples of using `INSERT INTO` with `VALUES`. mastering these techniques will help you build, maintain, and manipulate your databases with ease. Happy coding!