Help with SQL queries to build an iPhone app for SambaPOS

[Orders] holds all orders, with reference to [Tickets].
[Tickets] contains tickets.
[TicketEntities] contains Entities assigned to the Ticket, with reference to [Tickets].

Actual Ticket creation occurs when the Ticket is closed (orders submitted). Not to be confused with the Ticket having been Paid (or not).

When the Ticket is closed, updates are made to the Accounting tables.

See here for a general Overview (this does not depict DB relation however):