π Consultas avanzadas en MariaDB (Curso de MariaDB desde cero [16])
Buscar por un campo o por otro o por varios.
select * from tabla where campo1=2 or campo2=3 or campo3=5;
Buscar resultados donde el campo sea diferente a una valor.
select * from tabla where campo!=10 and campo 5;
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 el resultado de una operaciΓ³n matemΓ‘tica.
select * from tabla where campo=5+5;
Buscar resultados parecidos a un valor.
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
insert into alumnos (idSalon,nombre,fecha_ingreso) values
(6,βJuanβ,β2014-01-01β²),
(6,βJuanaβ,β2014-01-01β²),
(6,βJuanitoβ,β2014-01-01β²);
π Programador Novato: https://www.programadornovato.com/consultas-avanzadas-en-mariadb-curso-de-mariadb-desde-cero-16/
π¦ [CURSO] MYSQL DE 0 A 100π¬: https://www.youtube.com/playlist?list=PLCTD_CpMeEKQmH9cRKWWHahygZFtIdwYG
π¦ [CURSO] PhpMyAdmin En espaΓ±ol πͺπΈ: https://www.youtube.com/playlist?list=PLCTD_CpMeEKRDDCpQho7sg1iNYQpOy2G4
π Facebook: https://facebook.com/ProgramadorNovatoOficial
π Twitter: https://twitter.com/programadornova
π Linkedin: https://www.linkedin.com/in/programadornovato/
π Instagram: https://www.instagram.com/programadornovato/
π Pagina oficial: https://www.programadornovato.com
π Gracias por apoyar este canal: https://www.patreon.com/programadornovato
π¦ Canal de youtube: https://www.youtube.com/c/programadornovato
#MariaDB #mysql #Workbench