MYSQL count child table with other modifiers - help please! -


I have a ticket purchasing database and want to collect all the orders that meet certain criteria, and even then the total number Each order of the tickets 'ranks' in the 'Order_Tets' table, which matches the order ID, if I make a simple call to SQL, then this works SQL:

SQL A:

SELECT o. *, As the COUNT (OT. OrderTit ID) number
From the commands
Left join ORDOTTO OOderID = OT.Oder ID
By Group OderID
LIMIT 0, 30 < Br />

And this SQL also works - this is the basic SQL call with all the data that I want except numtix data:

SQL B:

SELECT o *,
IF (o.orderedbyID = '0', ob.fname, u.fname) AS obfname,
if (o.orderedbyID = '0', Ob.lname, u.lname) as Oblname
From order o, perfs p, order order by ob, user u
WHERE p.eventID = '2'
and p.perfID = o .perfID
and (( UNIX_TIMESTAMP (p.perfdatetime) - UNIX_TIMESTAMP (NOW ())>> 0)
and ob.orderID = o.orderID
and u.userID = o.orderedbyID
ORDER BY p.perfdatetime ASC
LIMIT 0, 30

But when I try to include SQL A in SQL A, I get errors:

SQL C: (does not work)

SELECT o *, Number as COUNT (OT. OrderTit ID),
if .orderedbyID = '0', ob.fname, u.fname) AS obfname,
IF (o .orderedbyID = '0', ob.lname, u.lname) as the nickname
from order o, perfs p, orders_orderedby ob, user u
oind idid = ot. order id OT Ond Odidad
WHEE p.eventID = '2'
and p perfID = o.perfID
and ((UNIX_TIMESTAMP (p.perfdatetime) - UNIX_TIMESTAMP ( NOW ()))> 0)
and ob.orderID = o.orderID
and u.userID = O.orderedbyID
order by p.perfdatetime ASC
Group OderID
LIMIT 0, 30

This is what I am Ruti joins:

# 1064 - is an error in your SQL syntax; My '' Group By '' needs to be implemented. "For the right syntax to use line 12 near the ORIDID limit 0, 30 'by the group, which matches your ISEQL server version, Check it out. To join the left and not the whole SQL, but this is an accurate estimate.

Any help is most appreciated!

after order : < / P>

  Group by o Order ID Order p.perfdatetime ASC LIMIT 0, 30  

Update:

  SELECT o *, As the COUNT (ot.OrderTicketID) number, if (O.orderedbyID = '0', ob.fname, u.fname) AS obfname, IF (o.orderedbyID = '0', ob.lname, u Lname) Order Orbnize order o Join perfs p ON p.perfID = Order O.perfID OR_Orded by ob.orderID = o.orderID UUU UI user U.IDIDID = O.Orded BIDAD ORDOTOTOT OT OR.OrdID = o Ordid P.E.E.E. TID = '2' and p.perfdatetime & lt; Now by () Group O. Order ID order by p.perfdatetime ASC LIMIT 0, 30  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -