I currently have this query set-up:
SELECT
topic.content_id,
topic.title,
image.location
FROM
mps_contents AS topic
INNER JOIN mps_contents as image
ON topic.content_id = image.page_id
WHERE
topic.page_id = (SELECT page_id FROM mps_pages WHERE page_short_name = 'foo' )
AND image.display_order = '1'
This is because I want to merge two rows from the same table in one row. This is a simplified setup of the table
-----------------------------------------------------------
| page_id | content_id | title | location | display_order |
-----------------------------------------------------------
| 1 | 200 | Foo | NULL | 200 |
| 200 | 201 | Bar | jpg.jpg | 1 |
-----------------------------------------------------------
And basically I want this result
---------------------------------
| content_id | title | location |
---------------------------------
| 200 | Foo | jpg.jpg |
---------------------------------
So Foo is the 200th topic on page 1 (Foo is treated as a subpage and all its contents are stored in the same table) and Bar is its featured image (featured only because it is the 1st image)
The query above effectively joins the two rows (it returns my desired result) but it also returns an extra row corresponding to the original row for Foo, that is, the location is NULL.
I hope someone could help me prevent the query from returning that extra row.
WHERE ... AND location IS NOT NULL