0% found this document useful (0 votes)
5 views

SQL Commands

The document outlines various SQL concepts including table manipulation, conditional queries using WHERE and logical operators, and string and date functions. It explains aggregate functions, joining tables, and the use of GROUP BY and HAVING clauses. Additionally, it covers sorting results and pattern matching in SQL queries.

Uploaded by

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

SQL Commands

The document outlines various SQL concepts including table manipulation, conditional queries using WHERE and logical operators, and string and date functions. It explains aggregate functions, joining tables, and the use of GROUP BY and HAVING clauses. Additionally, it covers sorting results and pattern matching in SQL queries.

Uploaded by

biswassubhayu1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1) ORIGINAL TABLE

TABLE 1
DISPLAY COLUMN WITH CHANGED NAME

DISPLAY AFTER MULTIPLYING WITH SCALER

2) ORIGINAL TABLE

TABLE 2
WE WILL DISPLAY NULL AS ALIVE
3) table 1 reference

PUTTING TEXT IN QUERY OUTPUT

4) WHERE CLAUSE

WE CAN OBTAIN SPECIFIC ROW(S) BASED ON SOME CONDITION USING WHERE CLAUSE.
5) RELATIONAL OPERATORS

=,>,<,>=,<=,<>(NOT EQUAL TO)

6) LOGICAL OPERATORS

(OR, AND, NOT)

IN FIRST CASE ANY SPECIES OUT OF DOG OR CAT IS PERMITTED BUT ONLY MALE SEX IS ALLOWED.
7) CONDITIONS BASED ON RANGE

WE HAVE TO USE WHERE CLAUSE AND BETWEEN CLAUSE

BETWEEN <AN INTEGER> AND <ANOTHER INTEGER>

8) CONDITIONS BASED ON LIST

WHEN WE USE IN CLAUSE, RECORDS WHERE OWNER WERE HAROLD AND GWEN WERE PICKED UP.

WHEN WE USED NOT IN CLAUSE, RECORDS WHERE OWNER WAS OTHER THAN HAROLD AND GWEN
WERE PICKED UP.

9) PATTERN MATCHES

PERCENT(%):CAN REPRESENT ANY SUBSTRING

UNDERSCORE(_): CAN REPRESENT A CHARACTER


Names of pet having four letter names

10) IS NULL

IS NOT NULL

11)SORTING RESULTS

ORDER BY CLAUSE
DESC: DESCENDING

ASC: ASCENDING(DEFAULT)

FOR STRINGS ARRANGMENT IS ON ALPHABETICAL ORDER

FOR INTEGERS IT IS ON THE BASIS OF THEIR VALUE


NAMES ARE IN ALPHABETICAL ORDER

ADDITIONAL CONDITION FOR MONTH HAS BEEN APPLIED.

STRING FUNCTIONS
 CHAR(): RETURNS THE CHARACTER OF EACH INTEGER PASSED

SELECT char(70,65,67,69);

2) CONCAT(): RETURNS CONCATENATED STRING.

3)LOWER()/LCASE(): RETURNS THE ARGUMENT IN LOWERCASE

4) UPPER()/UCASE: RETURNS THE ARGUMENT IN UPPER CASE

5) SUBSTR(): RETURNS SPECIFIED SUBSTRING


THE FIRST NUMBER IS THE INDEX. IN THIS CASE WE START FROM 3RD LEFT CHARACTER SO 3.

THE SECOND NUMBER IS HOW MANY CHARACTERS. IN THIS CASE WE WANT 4 CHARACTERS
INCLUDING THE THIRD LEFT ONE SO WE MENTION 4.

6) LTRIM: Removes leading whitespaces

RTRIM: Removes trailing whitespaces

TRIM: Removes both leading and trailing whitespaces

7) LENGTH: Returns the length of the string

DATE FUNCTIONS

 NOW():Returns the current system date and time

 DATE():Returns the date part of the date-time expression

 MONTH(date):Returns the month in numeric-form from the date


 MONTHNAME(date): Returns the month-name from the specified date

 YEAR(date): Returns the year from the specified date

 DAY(date): It return the day part from the date.

 DAYNAME(date): It returns the name of the day from the date

AGGREGATE FUNCTIONS

REFERENCE TABLE
 MAX(column): maximum values from a column
MIN(column): minimum values from a column

 SUM(column): sum of all the values from a column

 AVG(column): average of all the values from a column(the NULL values are not treated as
zero, they are treated as non-existent values. This means that in the formula for average as
follows: (sum/total records), total records are excluding the NULL values.)

 COUNT(*): no of records in a table

 COUNT(column): no of records in a column(excluding NULL)


JOINING OF TABLES
CARTESIAN PRODUCT

EQUIJOIN

EQUIJOIN CAN BE USED AS AN ALTERNATIVE TO NATURAL JOIN BY SELECTING SPECIFIC COLUMNS


AND MENTIONING THE NAME OF THE TABLE BEFORE THE COLUMN NAME WHENEVER THERE IS A
COMMON COLUMN.
NATURAL JOIN(NO COMMON COLUMN + EQUIJOIN)

GROUP BY AND HAVING


Group By:

HAVING ALWAYS USED AFTER GROUP BY.


WHERE ALWAYS USED BEFORE GROUP BY.
AGGREGRATE FUNCTIONS CAN NOT BE USED WITH WHERE CLAUSE.

USE OF WHERE CLAUSE


USE OF HAVING CLAUSE

WHAT HAPPENS WHEN WE USE OTHER NONAGGREGATED COLUMNS IN SQL

SECONDARY COLUMN IS DISPALYED AS MUL

You might also like