Instrucción SELECT

SQL TRANSACT: Uso de la instruccion SELECT

–USO DE LA INSTRUCCION SELECT
USE NORTHWIND
GO
SELECT DISTINCT COUNTRY FROM CUSTOMERS –DISTINCT MUESTRA SOLO VALORES UNICOS
–CLAUSULA DE RESTRICCION WHERE
SELECT * FROM CUSTOMERS
WHERE COUNTRY=‘GERMANY’
SELECT * FROM ORDERS
WHERE –comparadores > < >= <= BETWEEN Ó LIKE
ORDERDATE BETWEEN ‘1998-01-01’ AND ‘1998-31-12’ AND EMPLOYEEID=7
SELECT * FROM CUSTOMERS
WHERE COMPANYNAME LIKE ‘_e%’ — el simbolo _ sustituye una letra, % varias letras
select * from customers
where companyname like ‘[AD]%’ –todos los que comienzan con A ó con D
select * from customers
where companyname like ‘[A-D]%’ –todos los que comienzan con A, B, C, D
select * from customers
where companyname like ‘[^A]%’ –todos los que no comiencen con la letra A, [^]no contiene
SELECT * FROM CUSTOMERS
WHERE COUNTRY NOT IN( ‘BRAZIL’,‘GERMANY’,‘SPAIN’)–LOS QUE ESTEN CONTENIDOS
SELECT * FROM CUSTOMERS
WHERE COUNTRY NOT LIKE ‘B%’–TODOS LOS QUE NO COMIENCEN CON B, CUIDADO CON LOS ***NOT***
SELECT CUSTOMERID, COMPANYNAME, FAX FROM CUSTOMERS
WHERE FAX IS NOT NULL — DEVULVAME TODOS LOS REGISTROS DE FAX LLENOS
SELECT CUSTOMERID, COMPANYNAME, FAX FROM CUSTOMERS
WHERE FAX IS NULL — DEVULVAME TODOS LOS REGISTROS DE FAX VACIOS
SELECT COUNT(FAX) FROM CUSTOMERS –CUENTA SOLO LOS REGISTROS LLENOS, LOS VALORES VACIOS NO
——EJEMPLO—————————–
USE PUBS
SELECT TITLE_ID AS CODIGO,TITLE AS LIBRO,TYPE AS TIPO FROM TITLES — AS PARA RENOMBRAR
WHERE TYPE=‘psychology’ — UNA COLUMNA
ORDER BY LIBRO DESC
USE NORTHWIND
SELECT COUNTRY,CUSTOMERID,CONTACTNAME, CONTACTTITLE FROM CUSTOMERS
ORDER BY COUNTRY ASC , CUSTOMERID DESC — ORDER BY PARA ORDENAR LA VISTA
SELECT ‘NOMBRE COMPAÑIA: ‘+ COMPANYNAME + ‘, NOMBRE DEL CONTACTO: ‘
+ CONTACTNAME AS INFORMACION FROM CUSTOMERS — MODIFICANDO EL FORMATO AGREGANDO TEXTOS CONCATENADOS
———————–
SELECT CUSTOMERS.CUSTOMERID, CONTACTNAME, ORDERID, ORDERDATE
FROM CUSTOMERS INNER JOIN ORDERS
ON CUSTOMERS.CUSTOMERID = ORDERS.CUSTOMERID
ORDER BY ORDERID
——
SELECT
CUSTOMERID
–,COMPANYNAME
,CONTACTNAME
FROM CUSTOMERS

Leave a Reply

Your email address will not be published. Required fields are marked *