Trying to show customers' vehicles who had an invoice raised in the past 30 days.
I tried this:
select C.*, V.*
from CAR_OWNERSHIP O
join VEHICLE V on v.VEH_ID = O.VEH_ID
join CUSTOMER C on C.CUS_ID = O.CUS_ID
where exists (select null
from INVOICE I
where I.INV_ID = O.INV_ID and
I.INV_DATE >= date() - 30);
Im getting "syntax error in FROM clause"
I have quickly tried a query in access and I get the same error you get but when I change the JOIN to a specific join like LEFT OUTER JOIN or INNER JOIN then that error goes away but it is replaced with another
Syntax error (missing operator) in query expression in
I researched that and found this post which indicates that access requires parentheses when using more than one join
select *
from (CAR_OWNERSHIP O
left outer join CUSTOMER C on C.CUS_ID = O.Cus_ID)
left outer join VEHICLE V on v.VEH_ID = O.VEH_ID
where exists (select null
from INVOICE I
where I.INV_ID = O.INV_ID and
I.INV_DATE >= date() - 30);
I do hope this helps
Related
I am attempting a two left joins for on order_revenue_delta_history on comcat_product_d and sales_location_d.
I keeping getting the Syntax error: Expected end of input but got keyword ON at [7:1]. I tried putting it in (), and adding AND after b. so im not sure what it is I am doing wrong.
This is my code so far below. I haven't finished the filter yet which I wanted it to show quantity sold >=1. Just trying to get it to run. Am I doing the whole join wrong? I am trying to join multiple datasets.
SELECT
a. ll_quantity_sold,
b.product_type
FROM
`slb-it-sp-valuecapture-prod.ods_vc.order_revenue_delta_history` a
LEFT JOIN `slb-it-sp-valuecapture-prod.ear_aa_108.comcat_product_d` b,
`slb-it-sp-valuecapture-prod.ear_aa_108.sales_location_d` c
ON
( a.ll_product_id = b.product_id
AND a.location_id = c.location_id )
GROUP BY
product_type
LIMIT
1000
Try the following.
your left join is incorrect. You cannot join tables all together on single on.
SELECT
a.ll_quantity_sold,
b.product_type
FROM
`slb-it-sp-valuecapture-prod.ods_vc.order_revenue_delta_history` a
LEFT JOIN `slb-it-sp-valuecapture-prod.ear_aa_108.comcat_product_d` b
ON a.ll_product_id = b.product_id
LEFT JOIN `slb-it-sp-valuecapture-prod.ear_aa_108.sales_location_d` c
ON a.location_id = c.location_id
GROUP BY
product_type
LIMIT
1000
I am debugging some code for an MS Access program with a SQL backend. One of the queries is producing the following error: "the expression on click you entered as the event property setting produced the following error:
cannot join on Memo, OLE, or Hyperlink Object (master_export.item=vw_items.Item)"
This is the original code:
SELECT master_export_pt.commitment_number AS [Commitment Number],
Sum(master_export_pt.receipt_amount) AS Amount,
LocalLocation.Location_Name AS Child_Location_Name,
LocalLocation_1.Location_Name AS Parent_Location_Name,
BypassLocation.JNL_Sales AS ByPassSales,
BypassLocation.JNL_COGS AS ByPassCogs,
master_export_pt.order_type
FROM (((master_export_pt
INNER JOIN vw_items ON master_export_pt.item = vw_items.Item)
INNER JOIN BypassLocation ON master_export_pt.location_id = BypassLocation.location_id)
INNER JOIN LocalLocation ON BypassLocation.location_id = LocalLocation.Location_ID)
LEFT JOIN LocalLocation AS LocalLocation_1
ON LocalLocation.parent_location_id = LocalLocation_1.Location_ID
and tried changing the first JOIN to:
FROM (((master_export_pt, vw_items)
where (master_export_pt.item = vw_items.Item))
INNER JOIN BypassLocation ON master_export_pt.location_id = BypassLocation.location_id)
INNER JOIN LocalLocation ON BypassLocation.location_id = LocalLocation.Location_ID)
LEFT JOIN LocalLocation AS LocalLocation_1
ON LocalLocation.parent_location_id = LocalLocation_1.Location_ID
but now i get the "Syntax error in JOIN operation" error message. Is there a way to re-write the query without using nested JOIN statements?
Thank you to all who responded. I tried the following code and it seems to have done the trick:
SELECT
xxx.commitment_number AS [Commitment Number],
Sum(xxx.receipt_amount) AS Amount,
xxx.Location_Name AS Child_Location_Name,
xxx.Location_Name AS Parent_Location_Name,
xxx.JNL_Sales AS ByPassSales,
xxx.JNL_COGS AS ByPassCogs,
xxx.order_type
FROM (
SELECT * FROM
master_export_pt AS mept, vw_items AS vi, BypassLocation AS bl, LocalLocation AS ll
WHERE mept.item = vi.Item
AND mept.location_id = bl.location_id
AND bl.location_id = ll.Location_ID) AS xxx
LEFT OUTER JOIN LocalLocation AS ll1 ON xxx.parent_location_id = ll1.Location_ID
GROUP BY
xxx.commitment_number,
xxx.Location_Name,
ll1.Location_Name,
xxx.JNL_Sales,
xxx.JNL_COGS,
xxx.order_type;
I have an oracle SQL query and a slight problem. I need to check if an item has a PO# that it has at least 1 line item. The query below works however it returns a result for each line of transaction_lines and I need only une result. PS I tried DISTINCT but get an ODBC error.
SELECT ITEMS.NAME, INVENTORY_NUMBER.INVENTORY_NUMBER, INVENTORY_NUMBER.ON_HAND_COUNT, ITEMS.SALESDESCRIPTION, CONDITION.LIST_ITEM_NAME,
BRAND_PARTNER.LIST_ITEM_NAME, PPROGRAM.LIST_ITEM_NAME, ENTITY.NAME, PO.TRANSACTION_NUMBER, INVENTORY_NUMBER.RECEIVED_COST, ITEMS.SALESPRICE, IR.TRANSACTION_NUMBER,
INVENTORY_SOURCE.LIST_ITEM_NAME, LOCATIONS.NAME, INVENTORY_NUMBER.RECEIPT_DATE, PO.INTERNAL_MEMO, INVENTORY_NUMBER.REFERENCE_, TEST_RESULTS.LIST_ITEM_NAME,
INVENTORY_NUMBER.TEST_FILE_LINK, INVENTORY_NUMBER.CONNECT_TRADE_ID, INVENTORY_NUMBER.SOLD_DATE, INVENTORY_NUMBER.SOLD_PRICE, INVENTORY_NUMBER.MEMO, ITEMS.UPC_CODE, ITEMS.MPN,
ITEMS.ITEM_ID, INVENTORY_NUMBER.CLEI, INVENTORY_NUMBER.CERTIFICATION_REF_ID
FROM INVENTORY_NUMBER
INNER JOIN ITEMS ON INVENTORY_NUMBER.ITEM_ID = ITEMS.ITEM_ID
INNER JOIN TRANSACTIONS AS PO ON INVENTORY_NUMBER.PURCHASE_ORDER_ID = PO.TRANSACTION_ID
INNER JOIN TRANSACTIONS AS IR ON INVENTORY_NUMBER.ITEM_RECEIPT_ID = IR.TRANSACTION_ID
INNER JOIN TRANSACTION_LINES ON PO.TRANSACTION_ID = TRANSACTION_LINES.TRANSACTION_ID
INNER JOIN ENTITY ON TRANSACTIONS.ENTITY_ID = ENTITY.ENTITY_ID
INNER JOIN CONDITION ON INVENTORY_NUMBER.CONDITION_ID = CONDITION.LIST_ID
INNER JOIN BRAND_PARTNER ON INVENTORY_NUMBER.BRAND_PARTNER_ID = BRAND_PARTNER.LIST_ID
INNER JOIN PPROGRAM ON INVENTORY_NUMBER.PROGRAM_ID = PPROGRAM.LIST_ID
INNER JOIN INVENTORY_SOURCE ON INVENTORY_NUMBER.INVENTORY_SOURCE_ID = INVENTORY_SOURCE.LIST_ID
INNER JOIN LOCATIONS ON INVENTORY_NUMBER.LOCATION_ID = LOCATIONS.LOCATION_ID
INNER JOIN TEST_RESULTS ON INVENTORY_NUMBER.TEST_RESULTS_ID = TEST_RESULTS.LIST_ID
WHERE INVENTORY_NUMBER.ON_HAND_COUNT IS NOT NULL AND ((INVENTORY_NUMBER.PURCHASE_ORDER_ID IS NULL) OR (INVENTORY_NUMBER.PURCHASE_ORDER_ID IS NOT NULL AND TRANSACTION_LINES.TRANSACTION_LINE_ID IS NOT NULL))
you could also remove the join to the transaction_lines and instead of tl.TRANSACTION_LINE_ID IS NOT NULL use an exists clause
and exists (select 1 from transaction lines tl
where tl.transaction_id = po.transaction_id)
I would suggest using a GROUP BY to help limit your results. You could also if you are interacting with transactions in your query you must always remember that without limiting results based on the "main line" you will receive the header record and then a record for each individual line item.
If you were doing this with a saved search you could put the criteria as "main line = true". Since I don't understand your query entirely I can't advise where to put this limitation in.
I have 3 tables:
CP_carthead (idOrder)
CP_cartrows (idOrder, idCartRow)
CP_shipping (idCartRow, idShipping, dateShipped)
There can be multiple idCartRows per idOrder.
I want to get all orders where all its idCartRows exist in CP_shipping. This seems like it should be simple, but I haven't found much on the web.
Here's my query now:
SELECT
s.idOrder
, s.LatestDateShipped
FROM
CP_carthead o
LEFT OUTER JOIN (
SELECT
MAX(s.dateShipped) [LatestDateShipped]
, r.idOrder
FROM
CP_shipping s
LEFT OUTER JOIN CP_cartrows r ON s.idCartRow = r.idCartRow
GROUP BY
r.idOrder
) s ON o.idOrder = s.idOrder
Your query is returning rows from "s" and not the orders. Based on your question, I came up with this query:
select o.*
from CP_Carthead o
where o.orderId in (select cr.idOrder
from cp_cartrows cr left outer join
cp_shipping s
on cr.idCartRow = s.IdCartrow
group by cr.idOrder
having count(s.idCartRow) = COUNT(*)
)
The subquery in the in statement is getting orders all of whose cartrows are in shipping.
I am trying to pull two different values based on different criteria from the same table and in my Left Join of the same table it is not recognizing the SELECT statement.
The error is as follows:
Dynamic SQL Error
SQL error code = -104
Token unknown - line 7, char -1
SELECT.
The SQL Statement:
SELECT
b.dept,b.typ,c.brand,c.style,c.ext,c.description,
max(c.price),max(c.last_cost),sum(c.quan) "TOTAL INV",D.QUAN "WEB INV"
FROM
invt c
left outer join (
SELECT dept,typ,brand,style,ext,description,sum(quan) as d.quan
FROM invt WHERE store in ('997')
group by dept,typ,brand,style,ext,description) d
on (b.store = d.store and b.style = d.style and b.brand = d.brand)
LEFT OUTER JOIN
sku b
on c.style = b.style and c.brand = b.brand
where c.quan <> 0 or c.ord <> 0
GROUP BY
b.dept,b.typ,c.brand,c.style,c.ext,c.description
Try changing this line:
SELECT dept,typ,brand,style,ext,description,sum(quan) as d.quan
to this:
SELECT store,dept,typ,brand,style,ext,description,sum(quan) as quan
You do not need the d alias here.
UPDATE:
As #Jeremy Holovacs mentioned, you also seem to be using d.store for your join but it does not exist in your subquery.