Consultas avanzadas en MySQL Workbench (Curso de MySQL desde cero [16])🐬

Programador Novato
Programador Novato
13.2 هزار بار بازدید - 4 سال پیش - Buscar por un campo o
Buscar por un campo o por otro o por varios.
select * from tabla where campo1=2 or campo2=3 or campo3=5;
Buscar resultados diferentes a la búsqueda.
select * from tabla where campo!=10;
Buscar resultados diferentes a null.
select * from tabla where campo is not null ;
Buscar resultados cuyo valor esté entre dos valores.
select * from tabla where campo between 7 and 9;
Buscar resultados que estén dentro de un conjunto de valores.
select * from tabla where campoId in (2,3,4);
Buscar por un campo o por el resultado de una operación matemática.
select * from tabla where campo=5+5;
Buscar resultados parecidos a la búsqueda.
select * from tabla where campo like '%valor%';

Codigos:
select * from alumno;
select * from alumno where (idSalon=2 or idSalon=3 or idSalon=5 or idSalon=6) and nota=10;
select * from alumno where nota!=10;
ALTER TABLE alumno CHANGE COLUMN `nota` `nota` INT(11) NULL ;
select * from alumno where nota is not null ;
-- porque es mejor between
select * from alumno where nota=7 or nota=8 or nota=9;
select * from alumno where nota between 7 and 9;
select * from alumno where nota not between 7 and 9;
select * from alumno where nota not between 7 and 9;
select * from alumno where fecha_ingreso between '2020-01-01' and '2020-01-01';
-- IN
select * from alumno where idSalon in (2,3,4);
select * from salon where grado=2;
select * from alumno where idSalon in (select id from salon where grado=2);
-- where con operaciones matematicas
select * from alumno where nota=5+5; -- 5*2
select * from alumno where nombre like '%e%'; -- termine con e %e   comience con j j%
select * from alumno where nombre not like '%e%'; -- que no tenga letra e

INSERTAR REGISTROS:
insert into alumnos (idSalon,nombre,fecha_ingreso) values
(6,'Eden','2014-01-01'),
(6,'Pedro','2014-01-01'),
(6,'Ines','2014-01-01');

[CURSO] MYSQL DE 0 A 100🐬: [CURSO] MYSQL DE 0 A 100🐬

🔗 Facebook: Facebook: ProgramadorNovatoOficial
🔗 Twitter: Twitter: programadornova
🔗 Linkedin: LinkedIn: programadornovato
🔗 Instagram: Instagram: programadornovato
🔗 Pagina oficial: https://www.programadornovato.com
🔗 Gracias por apoyar este canal: Patreon: programadornovato
🎦 Canal de youtube: programadornovato
#mysql #workbench #db
4 سال پیش در تاریخ 1399/08/28 منتشر شده است.
13,294 بـار بازدید شده
... بیشتر