I'm using MySQL - subqueries are supported although I'd preferably like to do this w/a join:
I have two tables
compass_blocks
id (PK)
description
position
compass_blocks_position
blocks_id (FK)
pageID
I'm trying to grab the id and description fields from the table compass_blocks. I have an existing $id (from compass_blocks) as a PHP variable, and I want to grab all of the blocks that are in the same compass_blocks.position as the current $id I'm holding, but that also are on the same compass_blocks_position.pageID as the current $id OR that have compass_blocks_position.pageID = 'cps-all'
In pseudo:
SELECT DISTINCT cb.id, cb.description FROM compass_blocks AS cb
WHERE cb.position = @position@ AND (cbp.pageID = @pageID@ OR cbp.pageID = 'cps-all')
where @position@ represents the position of $id (only one position allowed) and @pageID@ represents the pageID of $id (there could be more than one, as blocks can be placed on multiple pages).
I've tried multiple variations of joins (I'm only capable of some very basic joins) and couldn't quite get it.