sql Flashcards
upercase = lowercase # are the same
SELECT first_name FROM patients where first_name like ‘C%’
SELECT first_name FROM patients where first_name like ‘c%’
like
SELECT first_name FROM patients where first_name like ‘C%’
between:
is >= <=
not ><
SELECT first_name, last_name,weight
FROM patients
WHERE weight BETWEEN 100 AND 120;
operation card
– Uso del operador AND
SELECT *
FROM your_table
WHERE condition1 AND condition2;
– Uso del operador OR
SELECT *
FROM your_table
WHERE condition1 OR condition2;
– Uso del operador NOT
SELECT *
FROM your_table
WHERE NOT condition;
con NULL nunca va =
update patients set allergies=’NKA’ where allergies is null
concatenar || && concat(, , ,)
SELECT first_name || ‘ ‘ || last_name FROM patients
SELECT
join on
SELECT table1.col1, table2.col3 where table
join on table2 table1.col2 = table2.col4
view all the tables => sql server
select * from sys.tables
select name from sys.tables
delete all elements of a table
delete Personas
drop table
drop table Personas
create a table with date
CREATE TABLE Personas ( last_name NVARCHAR(50),
birthday DATE
);
also works => string
CREATE TABLE Personas ( last_name NVARCHAR(50),
birthday NVARCHAR(50),
);
do questions
SELECT * FROM patients where Year(Birthday)=2010
count
SELECT count(*) FROM patients
max
example more complet
SELECT max(height) FROM patients
SELECT first_name,last_name,height FROM patients
where height= (SELECT max(height) FROM patients)
SELECT first_name,last_name,MAX(height) as height FROM patients
in
SELECT * FROM patients
where patient_id in (1,45,534,879,1000)
top
select top(10) * from Personas // in SQL SERVER
select * from Personas LIMIT 10 // in SQL normal
compare columns
SELECT * FROM admissions where admission_date = discharge_date
distinct
SELECT distinct(city) FROM patients /* all patients*/
SELECT distinct(city) FROM patients where province_id=’NS’
order by
SELECT * FROM patients order by height
SELECT * FROM patients order by height DESC
group by
los valores de ONE no se van a repetir => group by ONE
los valores de TWO no se van a repetir => group by ONE, TWO
SELECT year(birth_date) FROM patients group by year(birth_date)
alse work (important) in sql server dont work
SELECT * FROM admissions group by admission_date