0% found this document useful (0 votes)
4 views3 pages

SQL Basic Complete Syntax Queries Input Output

The document provides a comprehensive overview of basic SQL commands, including syntax, queries, and expected outputs. It covers essential operations such as creating tables, inserting data, selecting records, and using conditions like WHERE, AND, and LIKE. Additionally, it explains aggregate functions, grouping, ordering, and joining tables with examples relevant to a student database.

Uploaded by

keerthi28796
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

SQL Basic Complete Syntax Queries Input Output

The document provides a comprehensive overview of basic SQL commands, including syntax, queries, and expected outputs. It covers essential operations such as creating tables, inserting data, selecting records, and using conditions like WHERE, AND, and LIKE. Additionally, it explains aggregate functions, grouping, ordering, and joining tables with examples relevant to a student database.

Uploaded by

keerthi28796
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL BASIC COMMANDS – Syntax, Query, Input &

Output
Language: English + Tamil (Basic level, exam-ready)

Sample Input Table : student

sid name dept marks


1 Keerthi CSE 85
2 Arun ECE 78
3 Divya CSE 92
4 Ravi MECH 65
5 Karthi CSE NULL

1. CREATE TABLE

Syntax:
CREATE TABLE table_name (column datatype, ...);
Example:
CREATE TABLE student (sid INT, name VARCHAR(50), dept VARCHAR(30), marks INT);

2. INSERT INTO

Syntax:
INSERT INTO table_name VALUES (...);
Example:
INSERT INTO student VALUES (1,'Keerthi','CSE',85);

3. SELECT *

Query:
SELECT * FROM student;

Output

sid name dept marks


1 Keerthi CSE 85
2 Arun ECE 78
3 Divya CSE 92
4 Ravi MECH 65
5 Karthi CSE NULL
4. WHERE Condition

Query:
SELECT * FROM student WHERE dept='CSE';

Output

sid name dept marks


1 Keerthi CSE 85
3 Divya CSE 92
5 Karthi CSE NULL

5. AND Operator

Query:
SELECT * FROM student WHERE dept='CSE' AND marks > 80;

Output

name marks
Keerthi 85
Divya 92

6. LIKE Operator

Query:
SELECT * FROM student WHERE name LIKE 'K%';

Output

name
Keerthi
Karthi

7. BETWEEN

Query:
SELECT * FROM student WHERE marks BETWEEN 70 AND 90;

Output
name marks
Keerthi 85
Arun 78

8. Aggregate Functions

Query:
SELECT MAX(marks) FROM student;

MAX(marks)
92

9. GROUP BY

Query:
SELECT dept, COUNT(*) FROM student GROUP BY dept;

dept COUNT
CSE 3
ECE 1
MECH 1

10. ORDER BY

Query:
SELECT * FROM student ORDER BY marks DESC;

11. INNER JOIN

Query:
SELECT [Link], course.course_name FROM student INNER JOIN course ON [Link] =
[Link];
**Ithu full basic SQL commands – syntax, query, input & output oda complete PDF.**

Common questions

Powered by AI

JOIN operations are used in SQL to combine rows from two or more tables based on related columns. The INNER JOIN, specifically, returns rows when there is a match in both tables. For example, SELECT student.name, course.course_name FROM student INNER JOIN course ON student.sid = course.sid; merges student names with their corresponding course names when IDs match, effectively combining data from both tables .

The CREATE TABLE command is crucial for defining a new table structure in SQL databases, specifying the table's name and its columns with respective data types. An example command is: CREATE TABLE student (sid INT, name VARCHAR(50), dept VARCHAR(30), marks INT); It initializes a table called 'student' with columns for student ID, name, department, and marks, setting the foundation for data storage .

To sort the students by marks in descending order, you would use the ORDER BY clause with DESC keyword: SELECT * FROM student ORDER BY marks DESC; This query sorts the student table by the marks column in descending numerical order, displaying higher values first .

Aggregate functions like MAX(), MIN(), AVG(), SUM(), and COUNT() provide valuable insights by performing calculations on a set of values, returning a single value. For example, using SELECT MAX(marks) FROM student; gives the maximum marks scored, allowing identification of the highest scorer. Similarly, AVG() could be used to find average marks, providing an overall performance metric of students .

NULL values signify the absence of data and can complicate SQL queries because operations involving NULL usually result in NULL, affecting aggregations and conditions. Managing NULLs involves using IS NULL to check, or coalescing with another value using COALESCE(). For selection, using WHERE marks IS NOT NULL; filters out such records ensuring cleaner data sets and accurate calculations .

To identify the students who have scored above 80 in the CSE department, you can use the SQL query with the AND operator to specify both conditions: SELECT * FROM student WHERE dept='CSE' AND marks > 80; This query retrieves records where the department is CSE and marks are greater than 80 .

The GROUP BY clause groups records that share common field values and is used with aggregate functions. To find the number of students in each department, you would use the query: SELECT dept, COUNT(*) FROM student GROUP BY dept; This groups the students by department and counts the number of students within each department, providing a tally per department .

To retrieve students who have marks between 70 and 90, you can use the BETWEEN operator in a SQL query: SELECT * FROM student WHERE marks BETWEEN 70 AND 90; This command fetches all records where the marks are inclusive and within the specified range .

The LIKE operator is useful for searching for patterns within a text field. For instance, if you want to find students whose names start with the letter 'K', the query SELECT * FROM student WHERE name LIKE 'K%'; would achieve that. This operator allows flexible pattern matching that cannot be easily accomplished with basic equality checks .

SQL commands provide a robust toolkit for database management. CREATE TABLE initializes table structures for data organization. INSERT INTO adds records. SELECT queries fetch and manipulate data using conditions (WHERE, LIKE), and ordering (ORDER BY), allowing precise retrieval. GROUP BY and aggregate functions (MAX, COUNT) offer insights into data patterns. Modifying data involves UPDATE, while DELETE removes data. Overall, SQL's structured approach enables comprehensive data handling, maintaining database integrity and facilitating complex analyses .

You might also like