Practical guide for a beginner who wants to learn SQL, which is a quite important language for working with any RDBMS (Relational Database Management System) like Oracle, MySql, DB2 etc..
Serial Data Type & Sequence
Sequence Control
One Sequence for Two Tables
Reset Sequence
Array Data Type
Array Functions and Operands
Extension hStore
XML data
XML2 - Transform XML to Presentable view
JSON & JSONB
JSON Data Retrieving
Domain and Citext Extension
Write functions on Perl, Python, JS, Ruby, PHP
Produce nice outputs for graphical, tabular and textual reporting in R-Report...Dr. Volkan OBAN
REFERENCE:
http://davidgohel.github.io/ReporteRs/lists.html
ReporteRs is an R package for creating Microsoft (Word docx and Powerpoint pptx) and html documents. It does not require any Microsoft component to be used. It runs on Windows, Linux, Unix and Mac OS systems. This is the ideal tool to automate reporting generation from R.
در این جلسه از کلاس به ساختار های داده
Set, Tuple, Dictionary
پرداختیم
PySec101 Fall 2013 J3E1 By Mohammad Reza Kamalifard
Talk About :
Sets,Tuples and Dictionary Data Types in Python
What is the main difference between PostgreSQL and other open-source databases
Built in and custom data types in PostgreSQL
Constraint CHECK and why do we need it
Queries merging - UNION, INTERSECT and EXCEPT
PostgreSQL extensions - ltree, hstore etc.
Serial Data Type & Sequence
Sequence Control
One Sequence for Two Tables
Reset Sequence
Array Data Type
Array Functions and Operands
Extension hStore
XML data
XML2 - Transform XML to Presentable view
JSON & JSONB
JSON Data Retrieving
Domain and Citext Extension
Write functions on Perl, Python, JS, Ruby, PHP
Produce nice outputs for graphical, tabular and textual reporting in R-Report...Dr. Volkan OBAN
REFERENCE:
http://davidgohel.github.io/ReporteRs/lists.html
ReporteRs is an R package for creating Microsoft (Word docx and Powerpoint pptx) and html documents. It does not require any Microsoft component to be used. It runs on Windows, Linux, Unix and Mac OS systems. This is the ideal tool to automate reporting generation from R.
در این جلسه از کلاس به ساختار های داده
Set, Tuple, Dictionary
پرداختیم
PySec101 Fall 2013 J3E1 By Mohammad Reza Kamalifard
Talk About :
Sets,Tuples and Dictionary Data Types in Python
What is the main difference between PostgreSQL and other open-source databases
Built in and custom data types in PostgreSQL
Constraint CHECK and why do we need it
Queries merging - UNION, INTERSECT and EXCEPT
PostgreSQL extensions - ltree, hstore etc.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
Accelerate Enterprise Software Engineering with PlatformlessWSO2
Key takeaways:
Challenges of building platforms and the benefits of platformless.
Key principles of platformless, including API-first, cloud-native middleware, platform engineering, and developer experience.
How Choreo enables the platformless experience.
How key concepts like application architecture, domain-driven design, zero trust, and cell-based architecture are inherently a part of Choreo.
Demo of an end-to-end app built and deployed on Choreo.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
1. CREATE DATABASE database_name;
Then create connection with database. The connection is included in the names of the
database.
Create a Table: the following query creates a table
CREATE TABLE table_name
(
column_name1 data_type,
.......
)
CREATE TABLE email
(
LName varchar(20),
FName varchar(20),
email_add varchar(40)
)
INSERT INTO 'table_name'('field_name', 'field_name'. . .)
VALUES ('field_value', 'field_value'. . .);
INSERT INTO employee
VALUES ('Amar', 'Designer', 10000, 'amar@roseindia.com');
The output of the above code will be:
employee:
emp_name Position Salary email_id
Amar Designer 10000 amar@roseindia.com
Insert Data in Specified Columns
Let us consider we have a table named employee which have the following records:
emp_name Position Salary email_id
Amar Designer 10000 amar@roseindia.com
Let us consider we want to insert data in field name 'emp_name', 'Position' and in 'email_id'
with there specific values then we should use the following SQL statement:
INSERT INTO employee (emp_name, Position, email_id)
VALUES ('Vinod', 'Programmer', 'vinod@roseindia.com');
The output is like:
emp_name Position Salary email_id
Amar Designer 10000 amar@roseindia.com
Vinod Programmer vinod@roseindia.com
emp_name Position Salary email_id
Amar Designer 8000 amar@roseindia.com
If we want to change the salary to the employee with a emp_name of "Amar" then we should use the
following SQL statement :
Syntax:
UPDATE 'table_name' SET 'field_name' = 'new_value'
WHERE 'field_name' = 'field_value';
for example:
UPDATE Person SET Salary = 10000
WHERE emp_name = 'Amar';
The output of the above code will be :
emp_name Position Salary email_id
Amar Designer 10000 amar@roseindia.com
To Update several Columns in a Row: If we want to change the multiple values of a table like in employee
table we want to change Position and email_id then we have to write the following code in which we set
2. the email_id and position by SET keyword and putting condition by keyword WHERE for emp_name is
'Amar'.
UPDATE employee
SET email_id = 'amar@newsindia.com', Position = 'Programmer'
WHERE emp_name = 'Amar';
The output of the above code will be:
emp_name Position Salary email_id
Amar Programmer 10000 amar@newsindia.com
DELETE FROM table_name
WHERE column_name = some_value
Let's consider a table :
Person:
LName FName Address
ram Raj delhi-5
sonu Shiv delhi-5
To Delete a Row :
Suppose the row with Lname="sonu" is needed to get deleted
DELETE FROM Person WHERE LName = 'sonu'
Result
LName FName Address
ram Raj delhi-5
To Delete All the Rows : This means that the table structure, attributes, and indexes will be drop.
DELETE FROM table_name
SELECT column_name(s)
FROM table_name
Example: To select the content of columns named "LName" and "FName", from the database table called
"email", use a SELECT .
SELECT Name, Father_Name FROM EMAIL
The database table "email":
Name Father_Name Address
Ram Sonu delhi-5
Select All Columns: To select all columns from the "email" table, use a * symbol instead of column
names.
SELECT * FROM email
SELECT column FROM table
WHERE column operator value
The following operators can be used:
Operator Description
= Equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN If you know the exact value you want to return for at
least one of the columns
WHERE in SQL:
we add a WHERE to the SELECT statement:
SELECT * FROM Persons
WHERE unit='india'
In this section we are going to illustrate aggregate function, with the help of which we can use many
arithmetic operation like average, count, maximum and many more in SQL. They are briefly described and
denoted by the keyword in the given below section.
3. AVG
COUNT
MAX
MIN
SUM
For all of the above given function the standard code syntax will be:
SELECT "function type" ("column_name") FROM
"table_name"
For example we just take a Employee table and use the aggregate function SUM on the field "Salary" to
find out the total salary of the Employee table.
Table Employee:
emp_Name Salery Joining_Date
Amit 15000 Feb-05-2005
Chandan 25000 Feb-17-2005
Ravi 8000 Feb-25-2005
Vinod 7000 Feb-28-2005
To find out the total salary of the company's employee we should write the following code:
SELECT SUM (Salary) FROM Employee;
When we run the above query we will get the following result:
SUM(Salary)
55000
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',10);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 10
SQL % Wildcards Syntax
SELECT ColumnName(s)
FROM TableName
WHERE ColumnName LIKE pattern
SQL % Wildcards Query
Now we want to select the persons name those name starts with "k" from the table above.
select * from Stu_Table
where Stu_Name like 'k%'
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
1 Komal 10
Now we want to select the persons name those name ends with "h" from the table above.
select * from Stu_Table
where Stu_Name like '%h'
Result
Stu_Id Stu_Name Stu_Class
3 Rakesh 10
4. 5 Santosh 10
reate Table Stu_Class_10
create table Stu_Class_10(
Stu_Id integer(2) NOT NULL,
Stu_Name varchar(15),
Stu_Class varchar(10),
UNIQUE (id))
Insert data into Stu_Class_10
insert into Stu_Class_10 values(1,'Komal',10);
insert into Stu_Class_10 values(2,'Ajay',10);
insert into Stu_Class_10 values(3,'Rakesh',10);
insert into Stu_Class_10 values(4,'Bhanu',10);
insert into Stu_Class_10 values(5,'Santosh',10);
Stu_Class_10
Stu_Class_10
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Create Table Stu_Class_10
create table Stu_Class_10(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Create Table Stu_Class_12
create table Stu_Class_12(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Class_10
insert into Stu_Class_10 values(1,'Komal',10)
insert into Stu_Class_10 values(2,'Ajay',10)
insert into Stu_Class_10 values(3,'Rakesh',10)
insert into Stu_Class_10 values(4,'Bhanu',10)
insert into Stu_Class_10 values(5,'Santosh',10)
insert into Stu_Class_10 values(1,'Komal',10)
Insert data into Stu_Class_12
insert into Stu_Class_12 values(1,'Komal',12)
insert into Stu_Class_12 values(1,'Komal',12)
insert into Stu_Class_12 values(2,'Ajay',12)
insert into Stu_Class_12 values(3,'Rakesh',12)
insert into Stu_Class_12 values(4,'Bhanu',12)
insert into Stu_Class_12 values(5,'Santosh',12)
Stu_Class_10
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 10
Stu_Class_12
Stu_Id Stu_Name Stu_Class
1 Komal 12
1 Komal 12
2 Ajay 12
3 Rakesh 12
4 Bhanu 12
5 Santosh 12
SQL UNION Syntax
The SQL UNION Syntax used for union columns from two tables is given below:
SELECT column_name(s) FROM table_name1
UNION All
SELECT column_name(s) FROM table_name2
Use UNION in SQL Query
5. In this example, we union columns from two different tables. The UNION ALL combine two table using
select statement when both the table have the same name field and its data type. The select return you
all duplicate records from both tables. The UNION ALL command select all records from a tables.
.SELECT * FROM Stu_Class_10
UNION ALL
SELECT * FROM Stu_Class_12
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 10
1 Komal 12
1 Komal 12
2 Ajay 12
3 Rakesh 12
4 Bhanu 12
5 Santosh 12
Create Table Stu_Class_10
create table Stu_Class_10(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Create Table Stu_Class_12
create table Stu_Class_12(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Class_10
insert into Stu_Class_10 values(1,'Komal',10)
insert into Stu_Class_10 values(2,'Ajay',10)
insert into Stu_Class_10 values(3,'Rakesh',10)
insert into Stu_Class_10 values(4,'Bhanu',10)
insert into Stu_Class_10 values(5,'Santosh',10)
Insert data into Stu_Class_12
insert into Stu_Class_12 values(1,'Komal',12)
insert into Stu_Class_12 values(1,'Komal',12)
insert into Stu_Class_12 values(2,'Ajay',12)
insert into Stu_Class_12 values(3,'Rakesh',12)
insert into Stu_Class_12 values(4,'Bhanu',12)
insert into Stu_Class_12 values(5,'Santosh',12)
Stu_Class_10
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Stu_Class_12
Stu_Id Stu_Name Stu_Class
1 Komal 12
1 Komal 12
2 Ajay 12
3 Rakesh 12
4 Bhanu 12
5 Santosh 12
SQL UNION Syntax
The Syntax used for SQL UNION is used to selects only distinct values by default. The Syntax used for SQL
UNION is given below:.
SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
Use UNION in SQL Query
In this example, we make use of UNION in SQL Query, The UNION query return you the set of distinct
records from both the tables. The UNION operator only works with select statement, when both the table
6. have same field name and data type. The given below Query return you the distinct value from both the
tables.
SELECT * FROM Stu_Class_10
UNION
SELECT * FROM Stu_Class_12
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 12
2 Ajay 12
3 Rakesh 12
4 Bhanu 12
5 Santosh 12
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10));
Create Table Lib_Table
create table Lib_Table(Stu_Id integer(2), Lib_no integer(5));
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(8,'Tanuj',10);
Insert data into Lib_Table
insert into Lib_Table values(1,101);
insert into Lib_Table values(2,102);
insert into Lib_Table values(3,103);
insert into Lib_Table values(4,104);
insert into Lib_Table values(5,105);
insert into Lib_Table values(6,106);
insert into Lib_Table values(7,107);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
8 Tanuj 10
Lib_Table
Stu_Id Lib_no
1 101
2 102
3 103
4 104
5 105
6 106
7 107
SQL RIGHT JOIN Syntax
The SQL RIGHT JOIN Syntax display you all the records from the right table, even there are no matches
with the left table. The Syntax used for SQL RIGHT OUTER JOIN is given below:
SELECT column_name(s)
FROM table_name1
right JOIN table_name2
ON table_name1.column_name=table_name2.column_name
Use Right JOIN in SQL Query
7. The Example shows you the RIGHT JOIN in SQL Query. In this Example, we use RIGHT OUTER JOIN,
which displays the records from two tables. The table contain return all record from table1,even there are
no matches with the table 2.
select s.stu_id, s.stu_name, s.stu_class, l.lib_no
from stu_table as s Right JOIN lib_table as l
on l.stu_id = s.stu_id
Result
Stu_Id Stu_Name Stu_Class Lib_No
1 Komal 10 101
2 Ajay 10 102
3 Rakesh 10 103
4 Bhanu 10 104
5 Santosh 10 105
NULL NULL NULL 106
NULL NULL NULL 107
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
The insert into add the records or rows value to the table 'Stu_Table'.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',10);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 10
SQL IN Syntax
The SQL IN Syntax is used to return the records from table specify multiple values in WHERE Clause.
SELECT ColumnName(s)
FROM TableName
WHERE ColumnName IN(value1, value2,...)
SQL IN Query
The given below Query return you the records from table stu_table specifying multiple value in Stu_Name
containing name 'komal' and 'Rakesh'.
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
WHERE Stu_Name IN('Komal', 'Rakesh')
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
3 Rakesh 10
1 Komal 10
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15),
Stu_Class varchar(10), Stu_Dob Date)
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10,'1999,11,1');
insert into Stu_Table values(2,'Ajay',10,'1999,10,1');
insert into Stu_Table values(3,'Rakesh',10,'1999,11,1');
insert into Stu_Table values(4,'Bhanu',10,'1999,11,1');
insert into Stu_Table values(5,'Santosh',10,'1999,11,1');
Stu_Table
Stu_Id Stu_Name Stu_Class Stu_Dob
8. 1 Komal 10 1999-11-1
2 Ajay 10 1999-10-1
3 Rakesh 11 1999-11-1
4 Bhanu 11 1999-11-1
5 Santosh 12 1999-11-1
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',10);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 10
SQL LIKE Syntax
The SQL BETWEEN operator helps you to return a records between two values. The Syntax used in SQL
Like is given below:
SELECT ColumnName(s)
FROM TableName
WHERE ColumnName value1 between value2
SQL Like Operator Query
The SQL Like Operator Query is used to select the Stu_Table where a stu_Id between 1 and 3 from the
table.
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
WHERE Stu_Id BETWEEN 1 and 3
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
1 Komal 10
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',11);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 11
SQL AND Operator Syntax
The SQL AND Operator Syntax return you a filter records or rows from a table based on condition. The
Syntax used for SQL AND Operator is given as :
SELECT columnName(s)
9. FROM tableName
where condition1 AND conditions2
SQL AND Operator Query
The given SQL Query uses SQL AND Operator to fetch the record from table 'Stu_Table' based upon where
clause, which restricts the records from table based upon the AND operator condition. The AND operator
query return you a record only ,if the both condition specified in query are true. Otherwise, no records
fetch from a table.
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
where Stu_Id = 1 AND Stu_name = 'komal'
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
1 Komal 11
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10)
insert into Stu_Table values(2,'Ajay',12)
insert into Stu_Table values(3,'Rakesh',12)
insert into Stu_Table values(4,'Bhanu',12)
insert into Stu_Table values(5,'Santosh',12)
insert into Stu_Table values(1,'Komal',10)
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 12
3 Rakesh 12
4 Bhanu 12
5 Santosh 12
1 Komal 10
SQL AND Operator Syntax
The SQL AND Operator Syntax return you the filter record from a table based upon the condition specified
in the query.
SELECT columnName(s)
FROM tableName
where condition1 AND conditions2
SQL AND Operator Query
The given SQL Query help you to select only the Stu_Table with the Stu_Id equal to"1" AND
Stu_class="10".The AND operator fetch the records from a table, if both the condition are to be true. In
case, any one of the condition is false, fetch no records from table.
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
where Stu_Id = 1 AND Stu_Class = 10
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
1 Komal 10
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10)
insert into Stu_Table values(2,'Ajay',10)
insert into Stu_Table values(3,'Rakesh',10)
insert into Stu_Table values(4,'Bhanu',10)
insert into Stu_Table values(5,'Santosh',10)
insert into Stu_Table values(1,'Komal',10)
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
10. 4 Bhanu 10
5 Santosh 10
1 Komal 10
Syntax
The below Syntax helps you to fetch the records from the table. The Like query is used to find and
search for a specified records from a table in database..
SELECT ColumnName(s)
FROM TableName
WHERE ColumnName LIKE pattern
Query
The given below Query fetch the record from table 'Stu_Table using WHERE clause, which restrict the
records based upon the Like Query, that is used to find and search for a specific records from a table
Stu_Table.
The % (wildcard) is used to specify wildcards, which indicates missing letters in the pattern before and
after the pattern.
In this code, we want to select the Stu_Table begin with a stu_name "k" whose id is"1".The AND operator
is used to satisfy the both condition. If the both condition is true returns you a record from table. The
record display a Stu_Name begin with "k" whose id is "1".
select * from Stu_Table
where stu_name like 'k%'AND stu_id = 1
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
1 Komal 10
1. Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
SQL Alter Query
Alter table Stu_Table rename to Stu_Table_10)
2.
Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(10),
Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');
Stu_Table
+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
11. | 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
+--------+----------+-----------+
Describe Stu_Table
The Describe Stu_Table show you the field, data type, null etc of the table 'Stu_Table'.
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(2) | YES | | | |
| Stu_Name | varchar(10) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
+-----------+-------------+------+-----+---------+-------+
Alter column type Query
The Alter Table alter the table 'stu_Table' and MODIFY keywords modify the data type of Stu_Id(varchar
(2)) into Stu_Id( int(3)).
ALTER TABLE Stu_Table MODIFY Stu_Id int(3)
Describe Stu_Table
When you see the structure of table using Describe Stu_Table, the output is displayed as:
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| Stu_Id | int(3) | YES | | | |
| Stu_Name | varchar(10) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
+-----------+--------------+------+-----+---------+-------+
Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');
Stu_Table
+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
+--------+----------+-----------+
Describe Stu_Table
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(2) | YES | | | |
| Stu_Name | varchar(15) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
+-----------+-------------+------+-----+---------+-------+
Alter Column Size Query
ALTER TABLE Stu_Table MODIFY Stu_Id varchar(100)
Describe Stu_Table
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| Stu_Id | varchar(100) | YES | | | |
| Stu_Name | varchar(15) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
+-----------+--------------+------+-----+---------+-------+
12. Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(10),
Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');
Stu_Table
+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
+--------+----------+-----------+
Describe Stu_Table
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(2) | YES | | | |
| Stu_Name | varchar(10) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
+-----------+-------------+------+-----+---------+-------+
Alter column Not Null Query
ALTER TABLE Stu_Table MODIFY Stu_Id int(3)not null
Describe Stu_Table
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| Stu_Id | int(3) | No | | | |
| Stu_Name | varchar(10) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
+-----------+--------------+------+-----+---------+-------+
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15),
Stu_Class varchar(10) )
Insert data into Stu_Table
insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');
Stu_Table
+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
+--------+----------+-----------+
Syntax
The ALTER table statement in SQL is used to modify the table 'Stu_Table' and change keyword change
the name of field to new name of field. The syntax used for Alter Table is given below:
Alter table table_name change old_column_name new_column_name type size
Query
The Alter Table alter the table 'Stu_Table'. The change keyword change the column name of Stu_Id to Id
in table 'Stu_Table'.
Alter table Stu_Table change Stu_Id Id varchar(10)
13. Stu_Table
+--------+----------+-----------+
| Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
+--------+----------+-----------+
Create Table Stu_Table
create table Stu_Table( Stu_Id integer(2), Stu_Name varchar(15),
Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');
Stu_Table
+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
+--------+----------+-----------+
Describe Stu_Table
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(10) | YES | | | |
| Stu_Name | varchar(10) | YES | | NULL | |
| Stu_Class | varchar(5) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
Alter column Column Default Query
The Alter Table Keywords modify table'Stu_Table' and MODIFY keyword modify the data type of field
Stu_Id (varchar(10)) to Stu_Id(int(3)) and set the default value for this field is set '10'.Whenever you
leave a blank value in Stu_Id, This field would take default value of '10'.
ALTER TABLE Stu_Table MODIFY Stu_Id int(3) Default '10'
Describe Stu_Table
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| Stu_Id | int(3) | No | | 10 | |
| Stu_Name | varchar(10) | YES | | NULL | |
| Stu_Class | varchar(5) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
The insert into insert the records or row values into table 'Stu_Table'.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(6,'Tanuj',10);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
14. 3 Rakesh 10
4 Bhanu 10
5 Santosh 10
6 Tanuj 10
SQL ALTER Syntax
The SQL ALTER Syntax is used to modify the table and add a column name that you want to add and its
data type.
ALTER TABLE table_name
ADD column_name column-definition
SQL ALTER Query
The given below Query alter a table 'Stu_Table' and add keyword add a column Stu_Class whose data
type is varchar type.
Alter Table Stu_Table add Stu_Class varchar(10)
View data Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal NULL
2 Ajay NULL
3 Rakesh NULL
4 Bhanu NULL
5 Santosh NULL
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Create Table Lib_Table
create table Lib_Table(Stu_Id integer(2), Lib_no integer(5))
Insert data into Stu_Table
The insert into add the records or rows to the table 'Stu_Table' and 'Lib_Table'.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
Insert data into Lib_Table
insert into Lib_Table values(1,101)
insert into Lib_Table values(2,102)
insert into Lib_Table values(3,103)
insert into Lib_Table values(4,104)
insert into Lib_Table values(5,105)
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Lib_Table
Stu_Id Lib_no
1 101
2 102
3 103
4 104
5 105
SQL Alias Query
The given below SQL Query takes alias name for table 'Stu_Table' as s and 'Lib_Table' as l.
select s.stu_id, s.stu_name, s.stu_class, l.lib_no
from Stu_Table as s , Lib_Table as l
where s.stu_id = l.stu_id
Result
Stu_Id Stu_Name Stu_Class Lib_no
1 Komal 10 101
2 Ajay 10 102
15. 3 Rakesh 11 103
4 Bhanu 11 104
5 Santosh 12 105
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal')
insert into Stu_Table values(2,'Ajay')
insert into Stu_Table values(3,'Rakesh')
insert into Stu_Table values(4,'Bhanu')
insert into Stu_Table values(5,'Santosh)
Stu_Table
Stu_Id Stu_Name
1 Komal
2 Ajay
3 Rakesh
4 Bhanu
5 Santosh
SQL Add Column Syntax
The ALTER Table is used to modify table name 'table_name' and add a column at the specific position. The
first column specify the position of the column to be come first in table followed by a after column in a
table. The Syntax is given as :
ALTER TABLE table_name
ADD column_name column-definition [ FIRST | AFTER col_name ]
SQL Add Colum Query
The SQL Add Column Query add a Stu_Name column followed by Stu_Name in the Table Stu_Table.
Alter Table Stu_Table add Stu_Class int(10) AFTER Stu_Name
View data Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal NULL
2 Ajay NULL
3 Rakesh NULL
4 Bhanu NULL
5 Santosh NULL
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal');
insert into Stu_Table values(2,'Ajay');
insert into Stu_Table values(3,'Rakesh');
insert into Stu_Table values(4,'Bhanu');
insert into Stu_Table values(5,'Santosh);
Stu_Table
Stu_Id Stu_Name
1 Komal
2 Ajay
3 Rakesh
4 Bhanu
5 Santosh
SQL Add Column Syntax
The ALTER TABLE is used to alter the table table_name.The Add keyword is used to add a new column in a
table.
ALTER TABLE table_name
ADD column_name column-definition
SQL Add Colum Query
The given below example shows you a modified Stu_Table using Alter keywords, which add a new column
Stu_Class using add keyword, whose data is integer type.
Alter Table Stu_Table add Stu_Class int(10)
View data Stu_Table
16. Stu_Id Stu_Name Stu_Class
1 Komal NULL
2 Ajay NULL
3 Rakesh NULL
4 Bhanu NULL
5 Santosh NULL
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15),
Stu_Class varchar(10) default '10')
Insert data into Stu_Table
insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15))
Insert data into Stu_Table
The insert into add the records or rows into the table 'Stu_Table'.
insert into Stu_Table values(1,'Komal');
insert into Stu_Table values(2,'Ajay');
insert into Stu_Table values(3,'Rakesh');
insert into Stu_Table values(4,'Bhanu');
insert into Stu_Table values(5,'Santosh);
Stu_Table
Stu_Id Stu_Name
1 Komal
2 Ajay
3 Rakesh
4 Bhanu
5 Santosh
SQL Add Column Syntax
The Alter Table modifies and ADD Keywords add a new column to the table. The Syntax for the Add
Column is given as below:
ALTER TABLE table_name
ADD column_name column-definition
SQL Add Colum Query
The given below Query define a Alter Table that modifies and add a new column 'Stu_Class' to the table
'Stu_Table'.
Alter Table Stu_Table add Stu_Class varchar(10)
View data Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal NULL
2 Ajay NULL
3 Rakesh NULL
4 Bhanu NULL
5 Santosh NULL
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10));
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
17. insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',10);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 10
SQL LIKE Syntax
SELECT ColumnName(s)
FROM TableName
WHERE ColumnName LIKE pattern
SQL Like Operator Query
Now we want to select the persons name those name starts with "k" from the table above.
select * from Stu_Table
where stu_name like 'k%'
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
1 Komal 10
Now we want to select the persons name those name ends with "h" from the table above.
select * from Stu_Table
where stu_name like '%h'
Result
Stu_Id Stu_Name Stu_Class
3 Rakesh 10
5 Santosh 10
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10));
Insert data into Stu_Table
The Insert into statement add the records or rows into table 'Stu_Table'.
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(3,'Bhanu',10);
insert into Stu_Table values(4,'Santosh',10);
Stu_Table
The Select statement return you the records from a table 'Stu_Table'.
Records in the table:
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
SQL SELECT DISTINCT Syntax
The SQL Distinct clause can be used with the Select statement to get all unique records from database
SELECT DISTINCT columnName(s)
FROM tableName
SQL SELECT DISTINCT Query
You can run the following query to retrieve unique records from the table:
SELECT DISTINCT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table;
Result of the above query:
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
18. 3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Create Table Lib_Table
create table Lib_Table(Stu_Id integer(2), Lib_no integer(5))
Insert data into Stu_Table
The insert into add the records or rows to the respective tables.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(6,'Tanuj',10);
Insert data into Lib_Table
insert into Lib_Table values(1,101)
insert into Lib_Table values(2,102)
insert into Lib_Table values(3,103)
insert into Lib_Table values(4,104)
insert into Lib_Table values(5,105)
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
6 Tanuj 10
Lib_Table
Stu_Id Lib_no
1 101
2 102
3 103
4 104
5 105
SQL INNER JOIN Syntax
The INNER JOIN keyword is used to returns all rows from the left table (table_name1), even if there are
no matches in the right table (table_name2).The syntax for SQL INNER JOIN is given as :
SELECT column_name(s)
FROM table_name1
Left JOIN table_name2
ON table_name1.column_name=table_name2.column_name
Use INNER JOIN in SQL Query
In this example, the inner join is used to return the records from a tables 'Stu_Table'and 'Lib_Table' using
select statement. The select statement include the set of column records to be retrieved from both tables.
The Left Join is used to return all rows from the left table ,even if there is no matches in the right table.
select s.stu_id, s.stu_name, s.stu_class, l.lib_no
from stu_table as s Left JOIN lib_table as l
on l.stu_id = s.stu_id
Ruselt
Stu_Id Stu_Name Stu_Class Lib_No
1 Komal 10 101
2 Ajay 10 102
3 Rakesh 10 103
4 Bhanu 10 104
5 Santosh 10 105
6 Tanuj 10 NULL
Create Table Stu_Class_10
CREATE TABLE Stu_Class_10(
Stu_Id integer(2) NOT NULL,
19. Stu_Name varchar(15) NOT NULL,
Stu_Class varchar(10)) NOT NULL)
Insert data into Stu_Class_10 table
insert into Stu_Class_10 values(1,'Komal',10);
insert into Stu_Class_10 values(2,'Ajay',10);
insert into Stu_Class_10 values(3,'Rakesh',10);
insert into Stu_Class_10 values(4,'Bhanu',10);
insert into Stu_Class_10 values(5,'Santosh',10);
Stu_Class_10
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
Insert into statement insert the records into table.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',10);
Stu_Table
The select statement return you the record from table 'Stu_Table'.
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
1 Komal 10
SQL ORDER BY Syntax
The ORDER BY keyword sort the table result set by a specified column.
SELECT ColumnName(s)
FROM TableName
ORDER BY ColumnName(s)
SQL ORDER BY Query
In this Example, we use Order By Query on table 'Stu_Table'.The Order by Query return you the sorted
records from the table in ascending order by Stu_Name.
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
ORDER BY Stu_Name
Result
output of the above SQL Query will be
Stu_Id Stu_Name Stu_Class
2 Ajay 10
4 Bhanu 10
1 Komal 10
1 Komal 10
3 Rakesh 10
5 Santosh 10
SQL ORDER BY Query
In this example, we sort the records from a table in descending order by Stu_Id.
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
ORDER BY Stu_Id DESC
20. Result
Stu_Id Stu_Name Stu_Class
5 Santosh 10
4 Bhanu 10
3 Rakesh 10
2 Ajay 10
1 Komal 10
1 Komal 10
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
The insert into add the records or rows to the table Stu_Table.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',11);
insert into Stu_Table values(4,'Bhanu',11);
insert into Stu_Table values(5,'Santosh',12);
insert into Stu_Table values(1,'Komal',10);
Stu_Table
The select statement help you to display the table detail.
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 11
4 Bhanu 11
5 Santosh 12
1 Komal 10
SQL OR Operator Syntax
The SQL OR Operator is used to return a record if either the first condition is true or the second condition
is true. The Syntax used for SQL OR Operator is given below:
SELECT columnName(s)
FROM tableName
where condition1 OR conditions2
SQL OR Operator Query
In this example, we make use of OR Operator, which return the records from a table on the basis of
condition in WHERE Clause. The OR Operator return you a set of records,if either of the condition are
true.
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
where Stu_Id = 1 OR Stu_Class = 10
Result
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
1 Komal 11
Create Table Stu_Class_10
create table Stu_Class_10(
Stu_Id integer(2) NOT NULL,
Stu_Name varchar(15),
Stu_Class varchar(10),
PRIMARY KEY(Stu_Id))
Insert data into Stu_Class_10
The insert into statement is used to add the records or rows to the table 'Stu_Class_10'.
insert into Stu_Class_10 values(1,'Komal',10)
insert into Stu_Class_10 values(2,'Ajay',10)
insert into Stu_Class_10 values(3,'Rakesh',10)
insert into Stu_Class_10 values(4,'Bhanu',10)
insert into Stu_Class_10 values(5,'Santosh',10)
Stu_Class_10
Stu_Id Stu_Name Stu_Class
1 Komal 10
21. 2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Create Table Lib_Table
create table Lib_Table(Stu_Id integer(2), Lib_no integer(5))
Insert data into Stu_Table
The insert into add the records or rows to the respective tables.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
Insert data into Lib_Table
insert into Lib_Table values(1,101);
insert into Lib_Table values(2,102);
insert into Lib_Table values(3,103);
insert into Lib_Table values(4,104);
insert into Lib_Table values(5,105);
insert into Lib_Table values(6,106);
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Lib_Table
Stu_Id Lib_no
1 101
2 102
3 103
4 104
5 105
6 106
SQL INNER JOIN Syntax
The INNER JOIN keyword in SQL is used to returns you a row, when there is at least one match in both
table used in SQL Query. The Syntax used for SQL INNER JOIN is used as :
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
Use INNER JOIN in SQL Query
In this example, we make use of inner join. The inner join return you the records from both table ,when
there is atleast one match in both table respectively. The inner join is known as join. In this Query,both
the tables have stu_id as primary key, based on it, return all the record from the column enlisted in select
statement.
select s.stu_id, s.stu_name, s.stu_class, l.lib_no
from stu_table as s inner JOIN lib_table as l
on l.stu_id = s.stu_id
Ruselt
Stu_Id Stu_Name Stu_Class Lib_No
1 Komal 10 101
2 Ajay 10 102
3 Rakesh 10 103
4 Bhanu 10 104
5 Santosh 10 105
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10));
Create Table Lib_Table
22. create table Lib_Table(Stu_Id integer(2), Lib_no integer(5));
Insert data into Stu_Table
The insert into add the records value into your respective tables.
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
Insert data into Lib_Table
insert into Lib_Table values(1,101);
insert into Lib_Table values(2,102);
insert into Lib_Table values(3,103);
insert into Lib_Table values(4,104);
insert into Lib_Table values(5,105)
Stu_Table
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Lib_Table
Stu_Id Lib_no
1 101
2 102
3 103
4 104
5 105
SQL Alias Query
The given below example show you the SQL Alias Query. In this case, the alias name for Stu_Table is 's'
and Lib_Table is 'l'.As you can see the Alias Name Query make the table name simple and easier to write
and read.
select s.stu_id, s.stu_name, s.stu_class, l.lib_no
from Stu_Table as s , Lib_Table as l
where s.stu_id = l.stu_id
Result
Stu_Id Stu_Name Stu_Class Lib_no
1 Komal 10 101
2 Ajay 10 102
3 Rakesh 11 103
4 Bhanu 11 104
5 Santosh 12 105
Create Table Stu_Table
Create Table Stu_Table (Stu_Id varchar(2), Stu_Name varchar(15), Stu_Dob date);
Insert Data Into Stu_Table
The insert into statement add the records or rows into the table 'stu_table'.
insert into stu_table values('1', 'komal', '1984-10-27');
insert into stu_table values('2', 'ajay', '1985-04-19');
insert into stu_table values('3', 'santosh', '1986-11-16');
Stu_Table
+--------+----------+------------+
| Stu_Id | Stu_Name | Stu_Dob |
+--------+----------+------------+
| 1 | komal | 1984-10-27 |
| 2 | ajay | 1985-04-19 |
| 3 | santosh | 1986-11-16 |
+--------+----------+------------+
Query
The given below Query return you the record from a table 'Stu_Table'. The Where Query restrict select
Query and show you the record between ' '1984-01-01' And '1986-1-1'.
Select * From Stu_Table
23. Where Stu_Dob Between '1984-01-01' And '1986-1-1';
Result
+--------+----------+------------+
| Stu_Id | Stu_Name | Stu_Dob |
+--------+----------+------------+
| 1 | komal | 1984-10-27 |
| 2 | ajay | 1985-04-19 |
+--------+----------+------------+
create table statement create a table Stu_Table.
Create Table Stu_Table
SQL statement to create table :
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10),sub_id varchar(2),marks varchar(3));
Insert Data into Stu_Table
The insert into statement add the records or rows to the table 'Stu_Table'.
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10,1,45);
insert into Stu_Table values(2,'Ajay',10,1,56);
insert into Stu_Table values(3,'Rakesh',10,1,67);
insert into Stu_Table values(1,'Komal',10,2,47);
insert into Stu_Table values(2,'Ajay',10,2,53);
insert into Stu_Table values(3,'Rakesh',10,2,57);
insert into Stu_Table values(1,'Komal',10,3,45);
insert into Stu_Table values(2,'Ajay',10,3,56);
insert into Stu_Table values(3,'Rakesh',10,3,67);
insert into Stu_Table values(1,'Komal',10,4,65);
insert into Stu_Table values(2,'Ajay',10,4,56);
insert into Stu_Table values(3,'Rakesh',10,4,37);
insert into Stu_Table values(1,'Komal',10,5,65);
insert into Stu_Table values(2,'Ajay',10,5,46);
insert into Stu_Table values(3,'Rakesh',10,5,63);
Stu_Table
Records in the table:
+--------+----------+-----------+--------+-------+
| Stu_Id | Stu_Name | Stu_Class | sub_id | marks |
+--------+----------+-----------+--------+-------+
| 1 | Komal | 10 | 1 | 45 |
| 2 | Ajay | 10 | 1 | 56 |
| 3 | Rakesh | 10 | 1 | 67 |
| 1 | Komal | 10 | 2 | 47 |
| 2 | Ajay | 10 | 2 | 53 |
| 3 | Rakesh | 10 | 2 | 57 |
| 1 | Komal | 10 | 3 | 45 |
| 2 | Ajay | 10 | 3 | 56 |
| 3 | Rakesh | 10 | 3 | 67 |
| 1 | Komal | 10 | 4 | 65 |
| 2 | Ajay | 10 | 4 | 56 |
| 3 | Rakesh | 10 | 4 | 37 |
| 1 | Komal | 10 | 5 | 65 |
| 2 | Ajay | 10 | 5 | 46 |
| 3 | Rakesh | 10 | 5 | 63 |
+--------+----------+-----------+--------+-------+
Query
The given below syntax show you the average marks records of a numeric field in a table. The Group By
clause is used with the SQL aggregate functions and indicates the group where selected rows are placed.
select stu_id, stu_name,GROUP_CONCAT(marks) as marks,
sum(marks)as total ,avg(marks) as per
from stu_table group by stu_id;
Result
+--------+----------+----------------+-------+------+
| stu_id | stu_name | marks | total | per |
24. +--------+----------+----------------+-------+------+
| 1 | Komal | 45,65,47,65,45 | 267 | 53.4 |
| 2 | Ajay | 56,56,56,53,56 | 277 | 55.4 |
| 3 | Rakesh | 67,57,67,67,63 | 321 | 64.2 |
+--------+----------+----------------+-------+------+
SQL statement to create table:
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10),sub_id varchar(2),marks varchar(3));
Insert Data into Stu_Table
The insert into add the records or rows to the created table 'Stu_Table'.
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10,1,45);
insert into Stu_Table values(2,'Ajay',10,1,56);
insert into Stu_Table values(3,'Rakesh',10,1,67);
insert into Stu_Table values(1,'Komal',10,2,47);
insert into Stu_Table values(2,'Ajay',10,2,53);
insert into Stu_Table values(3,'Rakesh',10,2,57);
insert into Stu_Table values(1,'Komal',10,3,45);
insert into Stu_Table values(2,'Ajay',10,3,56);
insert into Stu_Table values(3,'Rakesh',10,3,67);
insert into Stu_Table values(1,'Komal',10,4,65);
insert into Stu_Table values(2,'Ajay',10,4,56);
insert into Stu_Table values(1,'Komal',10,5,65);
insert into Stu_Table values(3,'Rakesh',10,5,63);
Stu_Table
Records in the table:
+--------+----------+-----------+--------+-------+
| Stu_Id | Stu_Name | Stu_Class | sub_id | marks |
+--------+----------+-----------+--------+-------+
| 1 | Komal | 10 | 1 | 45 |
| 2 | Ajay | 10 | 1 | 56 |
| 3 | Rakesh | 10 | 1 | 67 |
| 1 | Komal | 10 | 2 | 47 |
| 2 | Ajay | 10 | 2 | 53 |
| 3 | Rakesh | 10 | 2 | 57 |
| 1 | Komal | 10 | 3 | 45 |
| 2 | Ajay | 10 | 3 | 56 |
| 3 | Rakesh | 10 | 3 | 67 |
| 1 | Komal | 10 | 4 | 65 |
| 2 | Ajay | 10 | 4 | 56 |
| 1 | Komal | 10 | 5 | 65 |
| 3 | Rakesh | 10 | 5 | 63 |
+--------+----------+-----------+--------+-------+
Query
The given below Query return you the records from table 'Stu_Table' and aggregate count for the table
field 'stu_name'. The Group By clause in this Query is used with aggregate functions and also specifies the
group 'stu_id' where selected rows are placed.
select stu_id, stu_name,
count(stu_name) from stu_table group by stu_id;
Result
+--------+----------+-----------------+
| stu_id | stu_name | count(stu_name) |
+--------+----------+-----------------+
| 1 | Komal | 5 |
| 2 | Ajay | 4 |
| 3 | Rakesh | 4 |
+--------+----------+-----------------+
Create Table Stu_Table
SQL statement to create table:
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
25. insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(6,'Tanuj',10);
Stu_Table
Records in the table:
Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
6 Tanuj 10
Describe Stu_Table
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(2) | NO | | | |
| Stu_Name | varchar(15) | YES | | | |
| stu_class | varchar(10) | NO | | | |
+-----------+-------------+------+-----+---------+-------+
Alter Table Primary Key Syntax
The table_name is the name of the table on which primary key is added.
The column_name is the name of the column on which primary key is created.
ALTER TABLE table_name
ADD PRIMARY KEY (column_name)
Alter Table Primary Key Query
The given Query show you an example to alter a table name 'Stu_Table' on which primary key is added.
The 'Stu_Id' is the name of the column on which primary key is created.
ALTER TABLE Stu_Table
ADD PRIMARY KEY (Stu_Id)
Describe Stu_Table
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(2) | NO | PRI | | |
| Stu_Name | varchar(15) | YES | | | |
| stu_class | varchar(10) | NO | | | |
+-----------+-------------+------+-----+---------+-------+
reate Table
SQL statement to create table:
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15), Stu_Class varchar(10));
Insert Data
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(6,'Tanuj',10);
Describe Stu_Table
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(2) | YES | | | |
| Stu_Name | varchar(15) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
+-----------+-------------+------+-----+---------+-------+
Stu_Table
Records in the table:
+--------+----------
+-----------+
| Stu_Id | Stu_Name | Stu_Class |
26. +--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
| 6 | Tanuj | 10 |
+--------+----------+-----------+
Add Multiple Columns Query
The Alter Table Query in SQL modifies the existing table 'Stu_Table' and add a multiple columns to the
existing table. In this example, we add columns 'Stu_dob' and 'Stu_Address' to the existing table
'Stu_Table'.
Alter Table Stu_Table add (Stu_dob date, Stu_Addreass varchar(20));
Describe Stu_Table
The Describe Stu_Table show you the new fields added to the table'Stu_Table'.
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| Stu_Id | varchar(2) | YES | | | |
| Stu_Name | varchar(15) | YES | | | |
| Stu_Class | varchar(10) | YES | | | |
| Stu_dob | date | YES | | | |
| Stu_Addreass | varchar(20) | YES | | | |
+--------------+-------------+------+-----+---------+-------+
Stu_Table
+--------+----------+-----------+---------+--------------+
| Stu_Id | Stu_Name | Stu_Class | Stu_dob | Stu_Addreass |
+--------+----------+-----------+---------+--------------+
| 1 | Komal | 10 | | |
| 2 | Ajay | 10 | | |
| 3 | Rakesh | 10 | | |
| 4 | Bhanu | 10 | | |
| 5 | Santosh | 10 | | |
| 6 | Tanuj | 10 | | |
+--------+----------+-----------+---------+--------------+
Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10),sub_id varchar(2),marks varchar(3));
Insert Data into Stu_Table
The insert into add the records or rows to the table'Stu_Table'.
insert into Stu_Table values(1,'Komal',10,1,45);
insert into Stu_Table values(2,'Ajay',10,1,56);
insert into Stu_Table values(3,'Rakesh',10,1,67);
insert into Stu_Table values(1,'Komal',10,2,47);
insert into Stu_Table values(2,'Ajay',10,2,53);
insert into Stu_Table values(3,'Rakesh',10,2,57);
insert into Stu_Table values(1,'Komal',10,3,45);
insert into Stu_Table values(2,'Ajay',10,3,56);
insert into Stu_Table values(3,'Rakesh',10,3,67);
insert into Stu_Table values(1,'Komal',10,4,65);
insert into Stu_Table values(2,'Ajay',10,4,56);
insert into Stu_Table values(3,'Rakesh',10,4,37);
insert into Stu_Table values(1,'Komal',10,5,65);
insert into Stu_Table values(2,'Ajay',10,5,46);
insert into Stu_Table values(3,'Rakesh',10,5,63);
Stu_Table
+--------+----------+-----------+--------+-------+
| Stu_Id | Stu_Name | Stu_Class | sub_id | marks |
+--------+----------+-----------+--------+-------+
| 1 | Komal | 10 | 1 | 45 |
| 2 | Ajay | 10 | 1 | 56 |
| 3 | Rakesh | 10 | 1 | 67 |
| 1 | Komal | 10 | 2 | 47 |
| 2 | Ajay | 10 | 2 | 53 |
| 3 | Rakesh | 10 | 2 | 57 |
27. | 1 | Komal | 10 | 3 | 45 |
| 2 | Ajay | 10 | 3 | 56 |
| 3 | Rakesh | 10 | 3 | 67 |
| 1 | Komal | 10 | 4 | 65 |
| 2 | Ajay | 10 | 4 | 56 |
| 3 | Rakesh | 10 | 4 | 37 |
| 1 | Komal | 10 | 5 | 65 |
| 2 | Ajay | 10 | 5 | 46 |
| 3 | Rakesh | 10 | 5 | 63 |
+--------+----------+-----------+--------+-------+
Query
The given below Query display you the records from table 'Stu_Table'. The 'sum(marks)' in the select
statement compute the sum of marks. The Group By Clause in this query returns you the group of
result-set by column name'stu_id'.
select stu_id, stu_name, sum(marks) as 'total marks'
from stu_table group by stu_id;
Result
+--------+----------+-------------+
| stu_id | stu_name | total marks |
+--------+----------+-------------+
| 1 | Komal | 267 |
| 2 | Ajay | 267 |
| 3 | Rakesh | 291 |
+--------+----------+-------------+
Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10),sub_id varchar(2),marks varchar(3));
Insert Data into Stu_Table
The Insert into statement add the records or rows to the table 'Stu_Table'.
insert into Stu_Table values(1,'Komal',10,1,45);
insert into Stu_Table values(2,'Ajay',10,1,56);
insert into Stu_Table values(3,'Rakesh',10,1,67);
insert into Stu_Table values(1,'Komal',10,2,47);
insert into Stu_Table values(2,'Ajay',10,2,53);
insert into Stu_Table values(3,'Rakesh',10,2,57);
insert into Stu_Table values(1,'Komal',10,3,45);
insert into Stu_Table values(2,'Ajay',10,3,56);
insert into Stu_Table values(3,'Rakesh',10,3,67);
insert into Stu_Table values(1,'Komal',10,4,65);
insert into Stu_Table values(2,'Ajay',10,4,56);
insert into Stu_Table values(3,'Rakesh',10,4,37);
insert into Stu_Table values(1,'Komal',10,5,65);
insert into Stu_Table values(2,'Ajay',10,5,46);
insert into Stu_Table values(3,'Rakesh',10,5,63);
Stu_Table
+--------+----------+-----------+--------
+-------+
| Stu_Id | Stu_Name | Stu_Class | sub_id | marks |
+--------+----------+-----------+--------+-------+
| 1 | Komal | 10 | 1 | 45 |
| 2 | Ajay | 10 | 1 | 56 |
| 3 | Rakesh | 10 | 1 | 67 |
| 1 | Komal | 10 | 2 | 47 |
| 2 | Ajay | 10 | 2 | 53 |
| 3 | Rakesh | 10 | 2 | 57 |
| 1 | Komal | 10 | 3 | 45 |
| 2 | Ajay | 10 | 3 | 56 |
| 3 | Rakesh | 10 | 3 | 67 |
| 1 | Komal | 10 | 4 | 65 |
| 2 | Ajay | 10 | 4 | 56 |
| 3 | Rakesh | 10 | 4 | 37 |
| 1 | Komal | 10 | 5 | 65 |
| 2 | Ajay | 10 | 5 | 46 |
| 3 | Rakesh | 10 | 5 | 63 |
+--------+----------+-----------+--------+-------+
28. Query
The Query below returns you the records from select statement. The GROUPCONCAT is used to combine
the result value of field. The max(marks) compute the maximum value of the field 'marks'.
select stu_id, stu_name, GROUP_CONCAT(marks) as marks ,
max(marks) from stu_table group by stu_id
Result
+--------+----------+----------------+------------+
| stu_id | stu_name | marks | max(marks) |
+--------+----------+----------------+------------+
| 1 | Komal | 45,65,47,65,45 | 65 |
| 2 | Ajay | 46,56,56,53,56 | 56 |
| 3 | Rakesh | 67,57,37,67,63 | 67 |
+--------+----------+----------------+------------+
Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10),sub1 integer(2),sub2 integer(2),
sub3 integer(2),sub4 integer(2),sub5 integer(2));
Insert Value Into Stu_Table
The insert into statement add the records or rows to the table.
insert into Stu_Table values(1, 'Komal', 10, 23, 34, 45, 56, 67);
insert into Stu_Table values(2, 'Ajay', 10, 34, 45, 56, 67, 78);
insert into Stu_Table values(3, 'Rakesh', 10, 23, 43, 45, 45, 34);
insert into Stu_Table values(4, 'Bhanu', 10, 56, 45, 67, 34, 54);
insert into Stu_Table values(5, 'Santosh', 10, 56, 67, 56, 67, 56);
insert into Stu_Table values(6, 'Tanuj', 10, 56, 45, 56, 56, 45);
Stu_Table
+--------+----------+-----------+------+------+------+------
+------+
| Stu_Id | Stu_Name | Stu_Class | sub1 | sub2 | sub3 | sub4 | sub5 |
+--------+----------+-----------+------+------+------+------+------+
| 1 | Komal | 10 | 23 | 34 | 45 | 56 | 67 |
| 2 | Ajay | 10 | 34 | 45 | 56 | 67 | 78 |
| 3 | Rakesh | 10 | 23 | 43 | 45 | 45 | 34 |
| 4 | Bhanu | 10 | 56 | 45 | 67 | 34 | 54 |
| 5 | Santosh | 10 | 56 | 67 | 56 | 67 | 56 |
| 6 | Tanuj | 10 | 56 | 45 | 56 | 56 | 45 |
+--------+----------+-----------+------+------+------+------+------+
Query
The given below Query returns you the records enlisted in select statement and sum of different numeric
field for each individual group of column values in the table 'Stu_Table'.
select stu_id, stu_name, sub1, sub2, sub3, sub4, sub5,
sum( sub1 + sub2 + sub3 + sub4 + sub5) as total
from stu_table group by stu_id;
Result
+--------+----------+------+------+------+------+------+-------+
| stu_id | stu_name | sub1 | sub2 | sub3 | sub4 | sub5 | total |
+--------+----------+------+------+------+------+------+-------+
| 1 | Komal | 23 | 34 | 45 | 56 | 67 | 225 |
| 2 | Ajay | 34 | 45 | 56 | 67 | 78 | 280 |
| 3 | Rakesh | 23 | 43 | 45 | 45 | 34 | 190 |
| 4 | Bhanu | 56 | 45 | 67 | 34 | 54 | 256 |
| 5 | Santosh | 56 | 67 | 56 | 67 | 56 | 302 |
| 6 | Tanuj | 56 | 45 | 56 | 56 | 45 | 258 |
+--------+----------+------+------+------+------+------+-------+
create the Table Stu_Table
SQL statement to create table:
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10));
Insert data into Stu_Table
Insert into keyword add the records or rows to the table 'Stu_Table'.
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
29. insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(6,'Tanuj',10);
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
Stu_Table
Records in the table:
+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
| 6 | Tanuj | 10 |
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
+--------+----------+-----------+
Query
The given Query return you the records and retrieve a single value, by calculate from values in a column
'stu_name' enlisted in the select statement from 'Stu_Table'. The group by keyword group all the records
which is grouped by attribute 'stu_id' from a table 'Stu_Table'.
select stu_name,count(stu_name) from stu_table group by stu_id;
Result
+----------+-----------------+
| stu_name | count(stu_name) |
+----------+-----------------+
| Komal | 4 |
| Ajay | 6 |
| Rakesh | 5 |
| Bhanu | 5 |
30. | Santosh | 4 |
| Tanuj | 1 |
+----------+-----------------+
Create the Table Stu_Table
SQL statement to create table:
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10));
Insert data into Stu_Table
Insert into keywords in SQL add the records or rows to the table 'Stu_Table'.
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(6,'Tanuj',10);
Stu_Table
Records in the table:
+--------+----------
+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1 | Komal | 10 |
| 2 | Ajay | 10 |
| 3 | Rakesh | 10 |
| 4 | Bhanu | 10 |
| 5 | Santosh | 10 |
| 6 | Tanuj | 10 |
+--------+----------+-----------+
Query
Next, the given below Query want to return the conditionally select the data from a table 'Stu_Table'. For
example, we want to retrieve the maximum value of the 'stu_id' with name search specified in the
'Stu_Name'. In order to overcome, we use the WHERE clause. The Syntax is given below:
select max(stu_id) from stu_table
where stu_name in('komal','ajay','santosh','rakesh');
Result
+-------------+
| max(stu_id) |
+-------------+
| 5 |
+-------------+
Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10),sub_id varchar(2),marks varchar(3));
Insert Data into Stu_Table
The insert into statement add the records or rows to the table 'Stu_Table'.
insert into Stu_Table values(1,'Komal',10,1,45);
insert into Stu_Table values(2,'Ajay',10,1,56);
insert into Stu_Table values(3,'Rakesh',10,1,67);
insert into Stu_Table values(1,'Komal',10,2,47);
insert into Stu_Table values(2,'Ajay',10,2,53);
insert into Stu_Table values(3,'Rakesh',10,2,57);
insert into Stu_Table values(1,'Komal',10,3,45);
insert into Stu_Table values(2,'Ajay',10,3,56);
insert into Stu_Table values(3,'Rakesh',10,3,67);
insert into Stu_Table values(1,'Komal',10,4,65);
insert into Stu_Table values(2,'Ajay',10,4,56);
insert into Stu_Table values(3,'Rakesh',10,4,37);
insert into Stu_Table values(1,'Komal',10,5,65);
insert into Stu_Table values(2,'Ajay',10,5,46);
insert into Stu_Table values(3,'Rakesh',10,5,63);
Stu_Table
+--------+----------+-----------+--------+-------+
| Stu_Id | Stu_Name | Stu_Class | sub_id | marks |
+--------+----------+-----------+--------+-------+
31. | 1 | Komal | 10 | 1 | 45 |
| 2 | Ajay | 10 | 1 | 56 |
| 3 | Rakesh | 10 | 1 | 67 |
| 1 | Komal | 10 | 2 | 47 |
| 2 | Ajay | 10 | 2 | 53 |
| 3 | Rakesh | 10 | 2 | 57 |
| 1 | Komal | 10 | 3 | 45 |
| 2 | Ajay | 10 | 3 | 56 |
| 3 | Rakesh | 10 | 3 | 67 |
| 1 | Komal | 10 | 4 | 65 |
| 2 | Ajay | 10 | 4 | 56 |
| 3 | Rakesh | 10 | 4 | 37 |
| 1 | Komal | 10 | 5 | 65 |
| 2 | Ajay | 10 | 5 | 46 |
| 3 | Rakesh | 10 | 5 | 63 |
+--------+----------+-----------+--------+-------+
Query
The Query return you a records and concatenated values from the field 'marks' from table 'Stu_table'. The
group by return the group records from a table 'Stu_Table'.
select stu_id,stu_name,GROUP_CONCAT(marks)
as marks from stu_table group by stu_id;
Result
+--------+----------+----------------+
| stu_id | stu_name | marks |
+--------+----------+----------------+
| 1 | Komal | 45,65,47,65,45 |
| 2 | Ajay | 46,56,56,53,56 |
| 3 | Rakesh | 67,57,37,67,63 |
+--------+----------+----------------+
Create Table Stu_Table
SQL statement to create table:
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15),
Stu_Class varchar(10), sub_id varchar(2), marks varchar(3));
Insert Data into Stu_Table
The insert into add the records or rows to the table 'Stu_Table'.
SQL statement to insert data into table:
insert into Stu_Table values(1,'Komal',10,1,45);
insert into Stu_Table values(2,'Ajay',10,1,56);
insert into Stu_Table values(3,'Rakesh',10,1,67);
insert into Stu_Table values(1,'Komal',10,2,47);
insert into Stu_Table values(2,'Ajay',10,2,53);
insert into Stu_Table values(3,'Rakesh',10,2,57);
insert into Stu_Table values(1,'Komal',10,3,45);
insert into Stu_Table values(2,'Ajay',10,3,56);
insert into Stu_Table values(3,'Rakesh',10,3,67);
insert into Stu_Table values(1,'Komal',10,4,65);
insert into Stu_Table values(2,'Ajay',10,4,56);
insert into Stu_Table values(3,'Rakesh',10,4,37);
insert into Stu_Table values(1,'Komal',10,5,65);
insert into Stu_Table values(2,'Ajay',10,5,46);
insert into Stu_Table values(3,'Rakesh',10,5,63);
Stu_Table
Records in the table:
+--------+----------+-----------+--------+-------+
| Stu_Id | Stu_Name | Stu_Class | sub_id | marks |
+--------+----------+-----------+--------+-------+
| 1 | Komal | 10 | 1 | 45 |
| 2 | Ajay | 10 | 1 | 56 |
| 3 | Rakesh | 10 | 1 | 67 |
| 1 | Komal | 10 | 2 | 47 |
| 2 | Ajay | 10 | 2 | 53 |
| 3 | Rakesh | 10 | 2 | 57 |
| 1 | Komal | 10 | 3 | 45 |
| 2 | Ajay | 10 | 3 | 56 |
| 3 | Rakesh | 10 | 3 | 67 |
32. | 1 | Komal | 10 | 4 | 65 |
| 2 | Ajay | 10 | 4 | 56 |
| 3 | Rakesh | 10 | 4 | 37 |
| 1 | Komal | 10 | 5 | 65 |
| 2 | Ajay | 10 | 5 | 46 |
| 3 | Rakesh | 10 | 5 | 63 |
+--------+----------+-----------+--------+-------+
Drop Table Query
The Drop Table Query delete the table 'Stu_Table' from database. The Table 'Stu_Table' is no longer to be
present in database.
Drop Table Stu_Table;