Queries
Queries
Data Types
• Text
• varchar
• Decimal(10,1)
• Decimal(s,d)
• The number of digits is specified in s. The digits after the decimal
point is specified as d.
Queries
1 soap 78 nmnmnmn
2 shampoo 10 nbnbnbnbnb
Database and Table Creation:
• Creating database:
• Create Database Ecommerce;
One Way
• Creating Table:
• Create Table Products (
• ID int (15) not null auto-increment,
• Name varchar (40) not null,
• Price decimal (10,4) not null,
• Description text ,
• Primary key(ID) );
Continued..
Other Way
• Create Table Products (
• ID int (15) not null auto-increment primary key,
• Name varchar (40) not null,
• Price decimal (10,4) not null,
• Description text );
Insert query
• Insert query
• Insert into Products (ID, name, price, decription) values (1,”shampoo”,1000,”dfdfdf”)
• Bulk Insertion:
• Insert into Products (ID, name, price, decription) values (1,”shampoo”,1000,”dfdfdf”),
(2,”soap”,1000,”dfdfdf”) , (3,”cream”,1000,”dfdfdf”) , (4,”lotion”,1000,”dfdfdf”) ;
• Count
Select count(names) city from user;
Gives count of values of the name column as an output
• Sum() output the sum of all values of selected column
• Avg() output the average of all values of selected column
• Min()return the minimum value of the column as a result
• Max()return the max value of the column as a result
IN Operator
Alias
• Select avg(price) as avgerageprice from products;
Output will be shown under avgerageprice heading
• IN Operator
• The IN operator allows you to specify multiple values in a WHERE
clause allowing you to test whether a specified value matches any
value in a list.
• The IN operator is a shorthand for multiple OR conditions.
E.g. column IN (v1, v2, v3) column = v1 OR column = v2 OR column = v3
• Select * from user where country IN(Pakistan, saudia,)
id name city country
1 ali sarhodha pakistan
2 amna lahore india
Like Operator