Return all records of non-given id if just one of those records matches
the given id of another field
After searching for a damn long time, I've not found a query to make this
happen.
I have an "offers" table with a "listing_id" field and a "user_id" field
and I need to get ALL the records for all listing_id's where at least one
record matches the given user_id.
In other words, I need a query that determines the listing_id's that the
given user is involved in, and then returns all the offer records of those
listing_id's regardless of user_id.
That last part is the problem. It's getting all the other user's offer
records to return when I'm only providing one user's id and no listing
id's
I was thinking of first determining the listing_ids in a separate query
and then using a php loop to create a WHERE clause for a second query that
would consist of a bunch of "listing_id = $var ||" but then I couldn't
bring myself to do it because I figured there must be a better way.
Hopefully this is easy and the only reason it has escaped me is because
I've had my head up my ass. Will be happy to get this one behind me.
Thanks for taking the time.
Josh
No comments:
Post a Comment