DEV Community

Cover image for Learning SQL for 30-days. Day 3.
Harriet Njoki
Harriet Njoki

Posted on

Learning SQL for 30-days. Day 3.

I might have lost track of time and but I will just time stamp based off what I can remember, bare with me;)

09:59 PM.
Today I learned how to create table and insert rows. [my code might not be clean yet, I am still figuring out how to write well organized clean code. But it is all written from memory]

Yesterday's learning also involved a bit of tables but it was only a touch up.
assuming you forgot to add a column/row in your data you can also do it by using the following prompt;

ALTER TABLE employees
ADD email VARCHAR(50)

SELECT * FROM employees
Enter fullscreen mode Exit fullscreen mode

And then you can click execute, then refresh your schema.

Today, it involves how to inserting rows, interchanging them and renaming data.

Assuming you didn't like how your table columns were arranged you can also change it up a bit by using the following query;

ALTER TABLE employees
MODIFY email VARCHAR(50)
AFTER last_name;

SELECT * FROM employees;
Enter fullscreen mode Exit fullscreen mode

Then click execute.

Here is and example of how you can insert rows and add some data into it;

INSERT INTO employees
VALUES (1, "Harriet", "Njoki", 24.56, "2023-11-09"),
      (2, "Elvis", "Odung", 21.43, "2023-09-23"),
      (3, "Daphne", "Edington", 22.43, "2024-02-13"),
      (4, "Elodie", "Walter", 22.43, "2024-05-10"),
      (5, "Austine", "Walker", 22.43, "2024-09-12");

SELECT * FROM employees;

Enter fullscreen mode Exit fullscreen mode

Click execute.
This has the employee ID, First name, Last name, hourly pay and date of hire. Followed by the SELECT ALL prompt where you can view your table and added content.

11:26 PM.

Next is how we can SELECT all the data from the table;

SELECT * FROM employees;
Enter fullscreen mode Exit fullscreen mode

But assuming you wanted a more specific data like for example, employee name, you could just use the following prompt;

SELECT first_name, last_name
FROM employees;
Enter fullscreen mode Exit fullscreen mode

Point being you can select specific columns depending on what you are looking for.

There is also the WHERE clause. This is for when you are looking for a specific type of data. Here is an example;

SELECT *
FROM employees
WHERE employee_id =1;
Enter fullscreen mode Exit fullscreen mode

This gives you a specific data minus everything else, but you just prompt it with whatever it is you are looking for.

01:25 AM.
I just wrote everything code I can remember at the top of my head, but I have to say, I am making progress.

The end.

Top comments (1)

Collapse
 
riettah profile image
Harriet Njoki

Any tips on how I could better myself are welcome and thank you;)