Posts

Showing posts with the label subquery

Joining Two Subqueries That Contain A Subquery

Joining Two Subqueries That Contain A Subquery Still new to SQL. I have looked around for an answer on this, and the examples that I have found, I have mirrored my query to look like the examples, and this query still isn't working. All Im trying to do is join two subqueries, but both of these subqueries contain a subquery inside. I'm receiving the following error: Msg 156, Level 15, State 1, Line 26 Incorrect syntax near the keyword 'On'. This is the query, please assist, thank you. Select * From ( Select * From( Select x.ID, x.Date, x.USOHist, x.OVXHist, Abs(Cast((((x.USOHist / NullIf((y.USOHist),0))-1)*100) as Decimal(10,2))) AS '%USOH', Abs(Cast((((x.OVXHist / NullIf((y.OVXHist),0))-1)*100) as Decimal(10,2))) AS '%OVXH' From (Select a.Date as aDate, Max(b.Date) As aPrevDate From USO_OVX_Hist a Inner Join USO_OVX_Hist b on a.Date > b.Date Group By a.Date) Sub1 Inner Join USO_OVX_Hist x on Sub1.aDate = x.Date Inner Join USO_OVX_Hist...

Mysql query for listing field values from one table to another

Mysql query for listing field values from one table to another I have the following mysql query: SELECT order_id, CONCAT(firstname, ' ', lastname) AS customer, shipping_code, total, currency_code, currency_value, date_added, date_modified FROM oc_order` o LEFT JOIN (select komercijalista from oc_customer (order.customer_id = customer.customer_id)) I am trying to list values from komercijalista field (which belongs to oc_customer table) in oc_order table. I am trying to connect them by customer_id which both have, but I am failing at left join. Any suggestions, please? Apart from learning mysql better, which I am already trying to do and this is where I need your help. Thanx. komercijalista oc_customer oc_order customer_id Help us help you - please share the tables structures, some sample data and the result you're trying to get – Mureinik Jun 29 at 10:39 ...