Search MySQl field created in the same query

2

Good morning. I have the following query:

select p.id_alumno as id,('estudiante') as tipo, p.url_imagen, concat_ws(' ',p.nombre,p.paterno,p.materno) as nombre,
        e.nombre as empresa,concat_ws(' ',u.nombre,u.apellidos) as solicitante, p.fecha_alta, p.estado
        from estudiantes p inner join usuarios u on p.id_alumno = u.id_usuario 
                 inner join empresas e on u.id_empresa = e.id_empresa

and I want to apply this where within the same query:

where tipo like 'estudiante'.

But it tells me that the field tipo does not exist.

How could I do this search, I would really appreciate your help.

PS: I already know that the query where will always return the same, but I have to resolve this error in order to continue what I am doing

    
asked by U.C 30.08.2018 в 20:17
source

2 answers

1

You can try with HAVING

select p.id_alumno as id,('estudiante') as tipo, p.url_imagen, concat_ws(' ',p.nombre,p.paterno,p.materno) as nombre,
        e.nombre as empresa,concat_ws(' ',u.nombre,u.apellidos) as solicitante, p.fecha_alta, p.estado
        from estudiantes p inner join usuarios u on p.id_alumno = u.id_usuario 
                 inner join empresas e on u.id_empresa = e.id_empresa HAVING tipo LIKE 'estudiante'

Do not forget the % in a LIKE, otherwise it would not make sense to use like.

More information from HAVING

link

    
answered by 30.08.2018 / 20:34
source
0

You can do it by putting the query in a sub-query and filter it in the result:

select * from (
        -- ejecutas la consulta en un sub-query
        select  p.id_alumno as id,
        ('estudiante') as tipo, 
        p.url_imagen, 
        concat_ws(' ',p.nombre,p.paterno,p.materno) as nombre,
        e.nombre as empresa,
        concat_ws(' ',u.nombre,u.apellidos) as solicitante,
        p.fecha_alta, p.estado
            from estudiantes p 
                inner join usuarios u on p.id_alumno = u.id_usuario 
                inner join empresas e on u.id_empresa = e.id_empresa

) t
where t.tipo like 'estudiante'

But, why do you want to make a like constant value? The value of the column tipo will always be the same so I do not see the need to make the comparison.

    
answered by 30.08.2018 в 20:20