How to find the data in SQL easily
A few easy ways to find the data in SQL easily from your tables — whether it’s just one column, all the data, or only certain rows.
SQL query to retrieve data from table :
SELECT clause is used to retrieve the data from table.
Example: The “player” Table
Imagine a table named player that stores basic details about players in a tournament. Here’s what the table looks like:
How to Create Tables in SQL- 5 Easy Ways for Beginners to Learn Databases
Name | Age | Score |
---|---|---|
Virat | 32 | 50 |
Rohit | 39 | 35 |
Dhoni | 44 | 30 |
We’ll use this table to demonstrate how to fetch data in SQL different ways.
Let’s explore more about the SELECT clause using the data base.
How do I SELECT only certain columns in SQL?
To retrieve the data only specific columns only from a table.How to find the data in SQL easily.
Syntax :
SELECT column1, column2, ... columnN FROM table_name;
1. Example of select command in sql :
Let’s fetch the name and score of the players from the player table. How to find the data in SQL easily.
SELECT name, score FROM player;
Output :
2. select all the columns in sql :
If you want to grab everything from the table — names, ages, scores — you can use an asterisk “*” to save time. How to find the data in SQL easily.
SELECT * FROM player;
Output:
3.How to find specific rows in SQL?
We use WHERE clause to retrieve only specific rows.
The WHERE part of helps to filter the results. Only showing rows that match the condition you give. How to find the data in SQL easily.
SELECT name, age FROM player WHERE name = 'Rohit';
Output:
What is the UPDATE command in SQL?
Update clause is used to update the data of an existing table in database. It allows us to change the value in one or more rows of a table.
How to update multiple values in SQL?
If you want to set the same value for a column across all rows, use this format:
Syntax:
UPDATE table_name SET column1 = value1;
Example of update command in sql :
UPDATE player SET score = 100;
How to update a single row in SQL?
If you want to update a row only when a condition is met, add a WHERE clause.
Syntax :
UPDATE table_name SET column1 = value1 WHERE column2 = value2;
Example update only one row in sql server :
Let’s say we want to update only the player named “Ram” and change his score to 150.
UPDATE player SET score = 150 WHERE name = 'Dhoni';
Here only update the score for the player named “Dhoni”.
SQL Summary :
Concept | Description |
---|---|
UPDATE | Modifies data in a table |
Update all rows | Leave out WHERE clause |
Update specific row | Use WHERE clause to target specific rows |
Case-insensitive | SQL keywords and identifiers can be uppercase or lowercase |
Delete table in SQL :
Delete clause is used to delete existing the records from table.
How do I DELETE all rows in a table in SQL?
Syntax :
DELETE FROM table_name;
Example delete all rows in sql server :
DELETE FROM player WHERE name = 'Dhoni';
Important Note:
Once data is deleted using the DELETE command, it cannot be recovered, so use it carefully!
What is a DROP TABLE command?
Drop clause is used to delete a table from the database.
Syntax :
DROP TABLE table_name;
Example drop table in sql server :
DROP TABLE player;
After running this command, the player table will be removed permanently from your database.
Command | Action |
---|---|
DELETE | Removes data from specific rows based on a WHERE condition. Table structure remains intact. |
DROP | Deletes the entire table including structure and all the data it holds. |
What is an ALTER TABLE in SQL?
ALTER clause is used to add, delete, or modify the columns in existing table.
Syntax :
ALTER TABLE table_name ADD column_name datatype;
Example of alter table in sql :
ALTER TABLE player ADD jersey_num INTEGER;
After this, the player table will have a new column called jersey_num. By default, all values in this column will be NULL.
How do you rename a column in SQL query?
Syntax :
ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;
Example of rename command in sql :
ALTER TABLE player RENAME COLUMN jersey_num TO jersey_number;
Now jersey_num is renamed to jersey_number.
How do I delete a column in SQL?
Syntax:
ALTER TABLE table_name DROP COLUMN column_name;
How to delete a column in SQL with an example?
ALTER TABLE player DROP COLUMN jersey_number;
How to find the data in SQL easily.
Got any questions or thoughts? Feel free to comment below. I’ll check it out and reply!