S-SQL Examples M

S-SQL Examples Home Page

Many to Many Calls

Many database records are linked in a many to many relationship with other tables or records. Consider the following query:

(query "select countries.id, countries.name, events.name as event
               from countries,events,countries_events
               where country_id=countries.id
                      and events.id=event_id
                      and events.id=$1"
  29)

This can be rephrased in s-sql as:

(query (:select 'countries.id 'countries.name
                (:as 'events.name 'event)
                :from 'countries 'events 'countries_events
                :where (:and  (:= 'country_id 'countries.id)
                              (:= 'events.id 'event_id)
                              (:= 'events.id '$1)))
       29)