0

Help needed please! I need to grab the entry_id’s relating to cat_id of ’42’, then find all cat_id’s that are attached to the entry_id’s we have just filtered by. I then need to get the cat_group_id of them cat_id’s. See screenshots of tables below:

enter image description here

enter image description here

EDIT

E.g. entry_id 92 has cat_id 42 assigned to it. But it also has 48 & 71. It's these numbers I need to output. But only if the entry_id is in cat_id 42

2
  • What all have you tried so far? Show the code you've tried that does not work for better results here. Commented Nov 10, 2015 at 11:42
  • Sadly, I'm not 100% on MySQL. The furthest I got was a simple Select, as well as trying to grab data from multiple tables. Nothing in the direction I needed really. Commented Nov 10, 2015 at 13:44

1 Answer 1

1

I didn't understand very well what you wanted, is it this?

select
  group_id
from
  exp_categories
inner join
  exp_category_posts
  on exp_category_posts.cat_id = exp_categories.cat_id
where
  entry_id in (select entry_id from exp_category_posts where cat_id = 42)
;

Note: I didn't create the tables to test it, but I think the query is ok

Sign up to request clarification or add additional context in comments.

2 Comments

Because I need to filter the entries down to see if they exist in cat_id 42 first. Then if they do, find all the other cat_id's assigned to the entry_id's that return true to cat_id = 42. If theres an easier way of doing this...
Amazing. That works. I didn't need the group_id but the cat_id in the end, so I just changed 'select group_id' to 'select exp_categories.cat_id' and that worked a charm! THANKYOU

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.