
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialDatabase
4.8 Rating 54 Questions 40 mins read6 Readers

In SQL, the database is an organized collection of structured information, known as data or information, which can be accessed electronically. A database is the topmost layer of data storage. Within a database, there are schemas and tables to store this information in an organized manner. An instance of a database can be created locally or on remote on-premise or cloud servers. The data present in the database can then be accessed using Structured Query Language or simply SQL.
SQL stands for Structured Query Language. It is a programming language used to access a relational database. Using SQL, we can create or modify databases, schemas, tables, or table entries. There are plenty of SQL server providers that have adopted SQL as the standard language for dealing with their databases.
A table organizes data in rows and columns similar to a spreadsheet. All the data in a database is contained within one or more table objects. To create a table, we must first select a database or create one if not already present.
To create a database –
CREATE DATABASE sql_demo;
To select the database –
USE sql_demo;
To create a table, we need to use the CREATE TABLE syntax which defines the columns, their datatypes and constraints for the table.
Following code demonstrates how to create a user table with the required columns –
CREATE TABLE user ( first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50), email_id VARCHAR(100) PRIMARY KEY, contact INT, created_on DATETIME );
An SQL table consists of rows and columns. Each row is known as a record and each column is known as a field. Each row or record represents a unique entry in the table whereas each column represents specific information for the respective record.
DBMS stands for Database Management System and RDBMS stands for Relational Database Management System. The major differences between the two are –
In order to run the SQL queries in an efficient and effective way, the query is executed in a specific order. Understanding the order of execution helps you to understand how the required data is being fetched from the database so that you can optimize your queries if required. The order of execution is provided as FROM à JOINS à WHERE à GROUP BY à HAVING à SELECT à ORDER BY à LIMIT.
Tip – You can memorise the order using the statement “From January We Gonna Have Sweet dishes OnLy”.
This is a frequently asked SQL Query interview questions for experienced professionals.
A foreign key, or a reference key, in SQL is used to link two tables in a database. The linkage is between one column from the first table to the primary key column present in another table. This helps to identify any value present in the column of the first table to the primary key column of another table maintaining the referential integrity. For example, table `students` consist of a field named, `course` which is a foreign key referencing to the primary key field `course_name` present in the `courses` table. The schema structure for this can be created using –
CREATE TABLE courses ( course_name VARCHAR(100) PRIMARY KEY, duration INT, language VARCHAR(50) ); CREATE TABLE students ( student_id INT PRIMARY KEY, name VARCHAR(50), course VARCHAR(100), FOREIGN KEY (course) REFERENCES courses (course_name) );
When two or more tables are to be linked together to create resultant data, we need to make use of joins. Using joins ensures that the resultant data matches the right record from one table to another. For example, if a database contains two tables, namely, student and scores, then we would like to join these tables by taking the student ID column as a reference (assuming student ID is present in both tables).
The different types of joins are –
1. INNER JOIN
Inner join matches one or more columns of a table with that of one or more tables and considers only those records from the tables which have the column values in common. For example, consider the student and scores table. When we apply inner join on both these tables using the student_id column, we get 3 records in the resultant table with student_id STU001, STU002 and STU003 since these IDs are common in both tables.
SELECT s.Student_ID AS Student_ID, First_Name, Last_Name, Class Marks, Grade FROM Student s JOIN Scores e ON s.Student_ID = e.Student_ID;
2. CROSS JOIN
Cross-join in SQL returns the cartesian product of the two tables. It joins each record from one table with the records in the other table. For example, consider table garment and table colours which are joined using a CROSS join. The resultant of the join will look like this –
3. FULL OUTER JOIN
FULL OUTER JOIN in SQL considers all the records from both the tables, i.e., both matching and non-matching ones. Where the match is not found the other table entries are provided with null values.
SELECT s.Student_ID AS Student_ID_X, e.Student_ID AS Student_ID_Y FROM Student s FULL OUTER JOIN Scores e ON s.Student_ID = e.Student_ID;
4. LEFT OUTER JOIN OR LEFT JOIN
Even if there are no matches in the right table, the SQL LEFT JOIN returns all rows from the left table. For the records in the left table where the match exists in the right table, the records are pulled otherwise the values in the data columns from the right table are represented as null for non-matching records. For example, the student_id STU001, STU002, and STU003 are common in both tables, therefore we can see them in the result along with STU005 id since it is present in the left table, that is, Students table.
SELECT s.Student_ID AS Student_ID, First_Name, Last_Name, Class Marks, Grade FROM Student s LEFT JOIN Scores e ON s.Student_ID = e.Student_ID;
5. RIGHT OUTER JOIN
The SQL RIGHT JOIN returns all rows from the left table, even if there are no matches in the right table. For the records in the right table where the match exists in the left table, the records are pulled otherwise the values in the data columns from the left table are represented as null for non-matching records. For example, the student_id STU001, STU002, and STU003 are common in both tables, therefore we can see them in the result along with STU010 id since it is present in the right table, that is, Students table.
SELECT s.Student_ID AS Student_ID, First_Name, Last_Name, Class Marks, Grade FROM Student s RIGHT JOIN Scores e ON s.Student_ID = e.Student_ID;
An index is a disk-based structure linked to a table or view that facilitates quicker row retrieval.
A table or view's table or view's columns are used to create keys in an index. These keys are kept in a structure (B-tree) that enables SQL Server to quickly locate the row or rows that correspond to the key values. The users cannot see the indexes, they are merely used to speed up queries. The CREATE INDEX statement is used to create indexes in tables.
Syntax:
CREATE INDEX index_name ON table_name (column_1, column_2, ... , column_N);
For indexing purposes, NULL values in a column are considered duplicate values if they are repeated more than once. Indexing is not possible if you have duplicate entries in a column. Therefore, creating a unique index in a column with NULL values is only possible if there is only one NULL value present in the respective field.
It's no surprise that this one pops up often in SQL Query interview questions for experienced.
A subquery is an additional query within an existing query. A subquery can be used in the SELECT, FROM, WHERE, and HAVING clauses and should be contained in parentheses. Subqueries in WHERE and HAVING clauses are classified into the following:
1. Independent subquery
The inner and outer queries are independent of one another in an independent subquery. Independent subqueries are further categorized into single-row and multiple-row types based on the number of returned rows. For example, the below query first executes the parenthesis to collect the average salary among the employees and then this value is further used to inspect the results of the outer query where the salary of an employee is greater than this average value.
SELECT Emp_id, Salary, Department FROM Employee e1 WHERE Salary ( SELECT AVG(Salary) FROM Employee e2);
2. Correlated subquery
A correlated subquery is a form of query where the execution of the inner query is dependent upon the outer query. An attribute from one of the tables in the outer query is used in the inner query. For each chosen record from the outer query, the inner query is run recursively. In the below example, the Department column of the outer sub-query is used inside the inner sub-query. Therefore, both the inner and outer queries are dependent or correlated.
SELECT Emp_id, Salary, Department FROM Employee e1 WHERE Salary ( SELECT AVG(Salary) FROM Employee WHERE e1.Department = e2.Department);