2

I not imagine how to build query. I need to select rows from table CONTENT which hasn't column tmplvarid=8 in left joined TEMPLATE VARIABLES column

SELECT con.id, con.alias, tv.tmplvarid FROM modx_site_content as con LEFT JOIN modx_site_tmplvar_contentvalues as tv ON con.id=tv.contentid WHERE con.deleted=0 AND (con.content IS NULL OR con.content='') AND con.template=5 AND tv.tmplvarid!=8/*not contains 8*/

Explanation: https://i.stack.imgur.com/gdgha.png

Fullstack
  • 135
  • 1
  • 1
  • 11

1 Answers1

1

Simple: Don't do an INNER join, do an OUTER JOIN instead:

SELECT con.id, con.alias, tv.tmplvarid FROM modx_site_content as con 
    LEFT OUTER JOIN modx_site_tmplvar_contentvalues as tv ON con.id=tv.contentid 
       AND tv.templvarid = 8 
         WHERE con.deleted=0 AND (con.content IS NULL OR con.content='') 
     AND con.template=5 AND tv.contentid IS NULL

So you join for templvarid = 8 in an OUTER JOIN - and then select (in where) only the rows that have NULL in tv. contentid (that's those where not templvarid 8 could be found for join)

Jan
  • 13,738
  • 3
  • 30
  • 55