π Selecting Data
Welcome to the Selecting Data module! This foundational learning path is designed to help you master the basics of querying data, particularly focusing on how to retrieve specific information from databases effectively.
π Creating SQL Tableβ
In this tutorial, you'll learn how to interpret and use rows in a database table. Tables are essential to storing structured data, and each row in a table represents a unique item or record.
Each row of a table represents a new item.
Each column of a table represents a specific attribute of the data, such as
id,name, orusername. These columns define the type of information stored for each item in the table.
For example, consider a table named Friends. Below is how a simple table might look:
info
- SQL Table
- SQL Code
- Output
Friends
| id | name | username |
|----|-----------------|------------------|
| 1 | John Doe | @johndoe |
| 2 | Jane Smith | @janesmith |
| 3 | Bob Johnson | @bobjohnson |
Creating SQL Tables & db.
-- creating database
CREATE DATABASE my_database;
-- use the database you created
USE my_database;
-- Create the table
CREATE TABLE friends (
id INT PRIMARY KEY,
name VARCHAR(100),
username VARCHAR(100)
);
-- Insert data into the table
INSERT INTO friends (id, name, username) VALUES
(1, 'John Doe', '@johndoe'),
(2, 'Jane Smith', '@janesmith'),
(3, 'Bob Johnson', '@bobjohnson');
| id | name | username |
|---|---|---|
| 1 | John Doe | @johndoe |
| 2 | Jane Smith | @janesmith |
| 3 | Bob Johnson | @bobjohnson |