I have two tables: Event
and Story
-- the former has info about an event and the latter has the story text of those events.
I can get all the story_id
of the events that involve Brazil from Event
like so:
SELECT @story_id := `story_id` FROM events
WHERE actor_id='Brazil';
Then I want to query Story
using the story_id
I got. How would I do that? Can I nest them somehow?
UPDATE: I ended up storing story_id
in a temporary table instead of a variable. (New to MySQL, I have no idea how variable works here...)
CREATE TEMPORARY TABLE IF NOT EXISTS temp_table AS (SELECT story_id FROM events
WHERE actor_id='Brazil');
Then
SELECT * FROM stories, temp_table
WHERE stories.StoryID = temp_table.story_id;
I'd appreciate any comment on this solution!