Pregunta

Tengo esta consulta:

(SELECT e.IdEvent,e.EventName,e.EventSubtitle,e.EventDescription,l.LocationName,e.EventVenue,EventStartDate,e.EventEndDate,e.EventHost,c.CategoryName,l.LocationCity,l.LocationState,e.isTBA,
(SELECT s.status FROM jos_rsevents_subscriptions s WHERE s.IdUser = 72 AND s.IdEvent = e.IdEvent LIMIT 1) as status 
FROM jos_rsevents_events e 
    LEFT JOIN jos_rsevents_locations l ON e.IdLocation=l.IdLocation 
    LEFT JOIN jos_rsevents_categories c ON e.IdCategory=c.IdCategory 
WHERE 1=1  AND status < 3 ) ORDER BY  EventStartDate

Pero me sale el error. " columna desconocida 'estado' en 'cláusula where'

¿Cómo puedo solucionar esto?

¿Fue útil?

Solución

Intente usar HAVING en su lugar, ya que eso se aplica después de ejecutar su subconsulta, por ejemplo:

(SELECT e.IdEvent,e.EventName,e.EventSubtitle,e.EventDescription,l.LocationName,e.EventVenue,EventStartDate,e.EventEndDate,e.EventHost,c.CategoryName,l.LocationCity,l.LocationState,e.isTBA,
(SELECT s.status FROM jos_rsevents_subscriptions s WHERE s.IdUser = 72 AND s.IdEvent = e.IdEvent LIMIT 1) as status 
FROM jos_rsevents_events e 
    LEFT JOIN jos_rsevents_locations l ON e.IdLocation=l.IdLocation 
    LEFT JOIN jos_rsevents_categories c ON e.IdCategory=c.IdCategory 
HAVING status < 3 ) ORDER BY  EventStartDate

Otros consejos

Si la tabla jos_rsevents_subscriptions tiene una clave principal, también puede hacer esto:

 SELECT e.IdEvent, e.EventName, e.EventSubtitle, e.EventDescription, 
     l.LocationName, e.EventVenue, EventStartDate, e.EventEndDate, 
     e.EventHost, c.CategoryName, l.LocationCity, l.LocationState, e.isTBA, 
     s.status     
 FROM jos_rsevents_events e     
    LEFT JOIN jos_rsevents_locations l 
       ON e.IdLocation=l.IdLocation     
    LEFT JOIN jos_rsevents_categories c 
       ON e.IdCategory=c.IdCategory 
    Left Join jos_rsevents_subscriptions s 
       On s.PK = (Select Max(PK) From jos_rsevents_subscriptions
                  Where IdUser = 72 
                     AND IdEvent = e.IdEvent)
 WHERE 1=1 AND status < 3  
 ORDER BY EventStartDate

P.S. ¿Por qué el 1 = 1 ??

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top