Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
MySQL get title from parentid with two tables

I will try to explain much as possible. here is my query..

SELECT * FROM mm_star_ratings s
JOIN mm_posts p ON s.post_id = p.postid
WHERE p.type='B'
ORDER BY s.rating DESC LIMIT 5

type='B' is the main post and type='C' is the reply on that post. There is a parentid column in mm_posts to set main post (B) id for C. Do I want to get the title from mm_posts if type='C' is there anyway?

The challenge for me is to get it work with my rating table where post_id is set for both B and C

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use Following query,

SELECT s.*,p.*, IF(p.type='C',pp.title,p.title) as title FROM mm_star_ratings s
JOIN mm_posts p ON s.post_id = p.postid Left Join mm_posts pp on pp.postid=p.parent_id 
ORDER BY s.rating DESC LIMIT 5
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda