Skip to content

Instantly share code, notes, and snippets.

@phillipadsmith
Created April 25, 2009 01:04
Show Gist options
  • Save phillipadsmith/101436 to your computer and use it in GitHub Desktop.
Save phillipadsmith/101436 to your computer and use it in GitHub Desktop.
Display the first-level elements of a story given its 'id'
SELECT f.id,ft.name,ft.key_name,f.place,f.object_order
FROM story_field f,field_type ft
WHERE f.field_type__id = ft.id and ft.active = 't'
and f.parent_id = (
select t.id from story_element t,element_type et,at_type at
where t.element_type__id=et.id and t.active='t' and et.active='t'
and et.type__id=at.id and t.object_instance_id = (
select max(id) from story_instance where story__id = 50706
)
and at.top_level='t'
) and f.active='t'
UNION
SELECT t.id,et.name,et.key_name,t.place,t.object_order
FROM story_element t,element_type et
WHERE t.element_type__id = et.id and et.active = 't'
and t.parent_id = (
select t.id from story_element t,element_type et,at_type at
where t.element_type__id=et.id and t.active='t' and et.active='t'
and et.type__id=at.id and t.object_instance_id = (
select max(id) from story_instance where story__id = 50706
) and at.top_level='t'
) and t.active='t'
ORDER BY place;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment