Tuesday, 9 June 2020

select

how to return upto 3 rows
SELECT * FROM Customers
WHERE ROWNUM <= 3;
SELECT * FROM Customers
LIMIT 3;
SELECT TOP 3 * FROM Customers;
SELECT TOP 50 PERCENT * FROM Customers;
WHERE Country='Germany';
WHERE Country='Germany'
LIMIT 3;
SELECT MIN(Price) AS SmallestPrice
FROM Products;










SELECT MAX(Price) AS LargestPrice
write largets price
FROM Products;
number
SELECT COUNT(column_name)
find how many rows
FROM table_name
WHERE condition;
SELECT AVG(column_name)
find avg of that row
FROM table_name
WHERE condition;
SELECT SUM(column_name)
FROM table_name
WHERE condition;
like
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
WHERE CustomerName LIKE 'a%'
Finds any values that start with "a"
WHERE CustomerName LIKE '%a'
Finds any values that end with "a"
WHERE CustomerName LIKE '%or%'
Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%'
Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a_%'
Finds any values that start with "a" and are at least 2 characters in length
WHERE CustomerName LIKE 'a__%'
Finds any values that start with "a" and are at least 3 characters in length
WHERE ContactName LIKE 'a%o'
Finds any values that start with "a" and ends with "o"
SELECT * FROM Customers
WHERE CustomerName NOT LIKE 'a%';
any thing is matched that will display
SELECT * FROM Customers
WHERE Country IN ('Germany''France''UK');
SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);
ist it will select suplieers table then it from tha t we got country so it will  if any country is matched in anohter table that will display
SELECT * FROM Customers
WHERE Country IN (SELECT Country FROM suppliers);
between
SELECT * FROM Products
11,12,13,14--19
WHERE Price BETWEEN 10 AND 20;
any nyumber is matched it will display
SELECT CustomerID AS ID, CustomerName AS Customer
FROM Customers;
change the column header names
       


SELECT CustomerName AS Customer, ContactName AS [Contact Person]
if name contan space requure brackets or double quotationif the alis contain spaces like contac and person some space is ther
FROM Customers;





SELECT CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address
FROM Customers;
select * from customers






No comments:

Post a Comment