How to Create a Database in SQL?
First, we create our database to execute the selected queries
Step 1: Creating the database
Use the below SQL query to create a database called geeks:
CREATE DATABASE geeks;
Step 2: Using the database
USE geeks;
Step 3: Table Creation
CREATE TABLE Employee
(
EmpID int,
FirstName varchar(255),
LastName varchar(255),
Salary INT
);
Step 4: Adding data to the table
INSERT INTO Employee VALUES(1, 'john' , 'ryther', 10000);
INSERT INTO Employee VALUES(2, 'Alex' , 'Hamilton', 20000);
INSERT INTO Employee VALUES(3, 'Sze' , 'Chauhan' , 10000);
INSERT INTO Employee VALUES(4,'Shiv', 'Chauhan', 50000);
Output:
Selecting Multiple Columns Based On Condition in SQL
In the real-world scenario where we have to select only columns from a given table, the columns selected can be single or multiple as per requirement. For Example: Write a query that gives the names of EMPLOYEE in an organization, so here we have to pick out only the name column from that particular EMPLOYEE table. Similarly, another example of multiple columns can be: Write a query which gives the names and salaries of all employees working in an organization. So here we have to select 2 columns of name and salary.
The examples above make us understand that the selection of columns is very important while learning SQL. First, we will learn how to select a single column from a table then we will move toward multiple columns.