0% found this document useful (0 votes)
7 views2 pages

SQL Pattern Matching and Queries Guide

The document discusses SQL pattern matching using the LIKE clause with wildcards for various string matching scenarios. It includes examples of SQL queries for selecting, updating, and creating tables, as well as aggregating data. Additionally, it demonstrates how to create a database and a table with specific attributes and constraints.
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)
7 views2 pages

SQL Pattern Matching and Queries Guide

The document discusses SQL pattern matching using the LIKE clause with wildcards for various string matching scenarios. It includes examples of SQL queries for selecting, updating, and creating tables, as well as aggregating data. Additionally, it demonstrates how to create a database and a table with specific attributes and constraints.
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

Pattern Matching : ( Like , Not Like ) SQL

Like clause is used to match pattern using two wild card characters
_ (underscore) – single unknown character
% (modulo) - Zero or more unknown characters (e.g.)
words staring with ‘t’ - ‘t%’
words ending with ‘t’ - ‘%t’
words containing ‘t’ - ‘%t%’
word with ‘t’ as second letter - ‘_t%’
words with ‘t’ as third last character - ‘%t_ _’
words containing four letter and ‘t’ as second letter - ‘_ t_ _’

Select BName , AVG(Rating) from Product P , Brand B


Where [Link] = [Link] GROUP BY BName
Having BName = “Medimix” OR BName = “Dove” ;

UPDATE Personal
set salary = salary + salary * 5 / 100
where Allowance IS NOT NULL ;
SELECT Name, Salary+Allowance AS “Total Salary”
FROM Personal ;

-----------------------
(a) select avg(salary) from employee group by deptid;
(c) select name from employee
where salary is null order by name ;
(d) select distinct deptid from employee ;

CREATE DATABASE PURCHASE ;


USE PURCHASE ;
CREATE TABLE ITEM
(ITEM_NO NUMERIC(14) PRIMARY KEY,
ITEM_NAME VARCHAR(25) NOT NULL UNIQUE,
ITEM_PRICE FLOAT(10,2),
ITEM_DOE DATE DEFAULT ‘2022-12-31’,
CUST_ID INT(15) REFERENCES CUSTOMER(CUST_ID));
Show Tables ;

You might also like