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

Consultas SQL - Ejemplos Online

The document provides SQL query examples for various operations such as INSERT, UPDATE, and SELECT on a database. It includes syntax for filtering results using conditions like LIKE, BETWEEN, and IN, as well as using mathematical operations and aliases. Additionally, it demonstrates how to handle multiple tables in queries and sort results using ORDER BY.

Uploaded by

amparocarrizo01
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

Consultas SQL - Ejemplos Online

The document provides SQL query examples for various operations such as INSERT, UPDATE, and SELECT on a database. It includes syntax for filtering results using conditions like LIKE, BETWEEN, and IN, as well as using mathematical operations and aliases. Additionally, it demonstrates how to handle multiple tables in queries and sort results using ORDER BY.

Uploaded by

amparocarrizo01
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
You are on page 1/ 2

Consultas SQL

Ejemplos sobre base de datos online:


https://www.w3schools.com/sql/trysql.asp?filename=trysql_asc

INSERT
INSERT INTO Products (ProductName,SupplierID,CategoryID,Unit,Price) VALUES ('Chocolate', 1, 1,
'1 kg box', 10)

Puedo consultar si se insertó de la siguiente forma: SELECT * FROM Products WHERE


ProductName LIKE 'Chocolate'

UPDATE
UPDATE Products SET ProductName = "Chocolate Blanco" WHERE ProductName LIKE 'Chocolate'

SELECT
SELECT * FROM Customers

SELECT customerid, customername, country FROM Customers

Agregar alias a columna y operaciones matemáticas en ellas. (+, -, *, /)


SELECT productid, productname, price, (price*1.21) as ConIVA FROM Products

SELECT con WHERE – Agrega condición a la consulta


LIKE – Compara con un patrón
SELECT customerid, customername, country FROM Customers WHERE country LIKE 'Argentina'

LIKE: _ -> Comodín de 1 digito, % -> Comodín varios dígitos


SELECT * FROM Products WHERE productname LIKE 'Ch%'

SELECT * FROM Products WHERE productname LIKE '_a%'

Operadores: >, <, =, <>, >=, <=


SELECT * FROM Products WHERE categoryid = 3

SELECT * FROM Products WHERE categoryid <> 3

BETWEEN
SELECT * FROM Products WHERE price BETWEEN 10 AND 15

IN
SELECT * FROM Products WHERE categoryid IN(1,2,3)

IS NULL
SELECT * FROM Customers WHERE address IS NULL

WHERE compuesto. Operador AND, OR – Varias condiciones en WHERE


SELECT * FROM Products WHERE categoryid IN(1,2,3) AND price > 10

SELECT * FROM Products WHERE categoryid = 1 OR price < 5


NOT – Negar en WHERE
SELECT * FROM Products WHERE categoryid NOT IN (1,2,3) AND price < 10

ORDER BY – Permite ordenar datos según una columna


SELECT * FROM Products WHERE categoryid NOT IN (1,2,3) AND price < 10 ORDER BY price DESC

SELECT ProductID, ProductName, SupplierID, CategoryID, Unit, Price, (Price*1.21) AS conIVA FROM
Products WHERE categoryid NOT IN (1,2,3) AND price < 10 ORDER BY conIVA DESC

Multitabla – Permite seleccionar columnas de varias tablas en simultaneo. TEMA A


PROFUNDIZAR.
SELECT P.productname, C.CustomerName, O.orderDate
FROM Customers C, Orders O, OrderDetails OD, Products P
WHERE O.customerID = C.customerID AND OD.OrderID = O.OrderID AND OD.productID =
P.productID AND P.productID = 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy