I have moved CMS to a new server and I had an error on some pages:
Unable to execute SELECT statement [SELECT SQL_CALC_FOUND_ROWS DISTINCT shop_products.id, shop_products.user_id, shop_products.route_id, shop_products.external_id, shop_products.active, shop_products.hit, shop_products.hot, shop_products.action, shop_products.archive, shop_products.brand_id, shop_products.category_id, shop_products.related_products, shop_products.old_price, shop_products.created, shop_products.updated, shop_products.views, shop_products.added_to_cart_count, shop_products.enable_comments, shop_products.tpl, shop_products_i18n.id, shop_products_i18n.locale, shop_products_i18n.name, shop_products_i18n.short_description, shop_products_i18n.full_description, shop_products_i18n.meta_title, shop_products_i18n.meta_description, shop_products_i18n.meta_keywords, IF(sum(shop_product_variants.stock) > 0, 1, 0) AS allstock FROM shop_products INNER JOIN shop_product_categories ON (shop_products.id=shop_product_categories.product_id) INNER JOIN shop_category ON (shop_products.category_id=shop_category.id) INNER JOIN shop_products_i18n ON (shop_products.id=shop_products_i18n.id AND shop_products_i18n.locale = :p1) INNER JOIN shop_product_variants ON (shop_products.id=shop_product_variants.product_id) LEFT JOIN shop_brands ON (shop_products.brand_id=shop_brands.id) WHERE shop_product_categories.category_id=:p2 AND shop_products.active=:p3 AND shop_products.archive=:p4 AND shop_category.active=:p5 GROUP BY shop_products.id ORDER BY allstock DESC,shop_product_variants.price DESC,shop_products.id DESC LIMIT 32]
I also fulfilled this request in PhpmyAdmin and got an errors of such a type:
Unexpected character. (near ":" at position 1093)
Please tell me, why there is no such error on one server, but on another server it's displayed?
It complains about this join
INNER JOIN shop_products_i18n ON (shop_products.id=shop_products_i18n.id AND shop_products_i18n.locale = :p1)
make sure you're passing p1 as an argument or join on a specific column instead of passing an argument?
Related
I'm Trying to replicate queries on DOMO from microsoft acccess. I assumed I had got the correct syntax but now I'm getting a The database reported a syntax error. Not unique table/alias: 'ga_wip_due_within_one_week'
SELECT `egl_inv`.Category, `egl_inv`.StyleClass, `egl_inv`.StyleMaster,
`egl_inv`.StyleMasterDesc, `egl_inv`.Color, `egl_inv`.ColorDesc,
`egl_inv`.Size,`egl_inv`.GscSku, `egl_inv`.UPC, `egl_inv`.RedistributionFlag,
`egl_inv`.Date_Soldout, `egl_inv`.GGS, `egl_inv`.Core, `egl_inv`.CartonQty,
If(IsNull(`ga_inv`.SumOfQty=True),0,`ga_inv`.SumOfQty) AS GA_INV,
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True),
0,`ga_wip_due_within_one_week`.SumOfQty_Size_Open) AS GA_WIP,
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True)
,0,`ga_wip_due_within_one_week`.`SumOfQty_Size_Open`.SumOfQty_Size) AS CUT,
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`) AS SS,
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`.`Demand`) AS
Demand, If(IsNull(`openorder`.OpenOrders=True),0,`openorder`.OpenOrders) AS
OpenOrders, If(IsNull(`egl_inv`.SumOfQty=True),0,`egl_inv`.SumOfQty) AS
EGL_INV,
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`.Demand)
AS AvgWklyFcst
FROM `averageweeklyfcst`
RIGHT JOIN (OpenOrders RIGHT JOIN (((((`egl_inv`
LEFT JOIN `ga_inv`ON `egl_inv`.GscSku = `ga_inv`.GscSku)
LEFT JOIN `ga_wip_due_within_one_week` ON `egl_inv`.GscSku =
`ga_wip_due_within_one_week`.GscSku) LEFT JOIN `ga_wip_due_within_one_week`
ON `egl_inv`.GscSku = `ga_wip_due_within_one_week`.GscSku)
LEFT JOIN `averageweeklyfcst` ON `
egl_inv`.GscSku = `averageweeklyfcst`.GscSku)
LEFT JOIN Demand ON `egl_inv`.GscSku = `averageweeklyfcst`.GscSku) ON
`openorder`.GscSku = `egl_inv`.GscSku) ON
`averageweeklyfcst`.GscSku = `egl_inv`.GscSku
GROUP BY EGL_INV.Category, `egl_inv`.StyleClass, `egl_inv`.StyleMaster,
`egl_inv`.StyleMasterDesc, `egl_inv`.Color, `egl_inv`.ColorDesc,
`egl_inv`.Size, `egl_inv`.GscSku, `egl_inv`.UPC,
`egl_inv`.RedistributionFlag, `egl_inv`.Date_Soldout, `egl_inv`.GGS,
`egl_inv`.Core, `egl_inv`.CartonQty,
If(IsNull(`ga_inv`.SumOfQty]=True),0,`ga_inv`.SumOfQty),
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True),
0,`ga_wip_due_within_one_week`..SumOfQty_Size_Open),
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True)
,0,`ga_wip_due_within_one_week`.SumOfQty_Size),
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`),
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`),
If(IsNull(`openorder`.OpenOrders=True),0,`openorder`.OpenOrders),
If(IsNull(`egl_inv`.`SumOfQty`=True),0,`egl_inv`.`SumOfQty`),
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`.`Demand`);
The database reported a syntax error. Not unique table/alias: 'ga_wip_due_within_one_week'
You have in the middle following line
LEFT JOIN `ga_wip_due_within_one_week` ON `egl_inv`.GscSku =
`ga_wip_due_within_one_week`.GscSku) LEFT JOIN `ga_wip_due_within_one_week`
as you see you add both without an aliais for the second ad something like as
ga_wip_due_within_one_week_1 for the second
I need to add a join 'level' to a pre-existing SQL query... unfortunately I keep getting errors with this query. I'm proabably falling somewhere but I cannot understand how to fix it.
The original query is the following:
SELECT
noleggio.*,
nome AS convenzionato
FROM
anag_convenzionati
RIGHT JOIN (SELECT
noleggio.*, targa, dc_standard AS dcstandard
FROM
veicoli_contratti
RIGHT JOIN (SELECT
noleggio.*,
nome AS assicurazione_pagante
FROM
anag_assicurazioni
RIGHT JOIN (SELECT
fatt_sconto_noleggio,
fatt_prezzo_noleggio,
id AS idnoleggio,
numero,
serie,
id_convenzionato,
stato_noleggio,
modalita_noleggio,
conducente,
locatario,
locazione_in_proprio,
id_assicurazione_pagante,
id_veicolo,
giorni,
fatt_giorni_noleggio,
fatt_prezzo_totale_noleggio,
data_pagamento_cliente_a_convenzionato,
ore_manodopera,
IF(locazione_in_proprio = 1, conducente, locatario) AS cedente
FROM
noleggio_veicoli
WHERE
((data_cancellazione IS NULL) OR (data_cancellazione = ''))
) AS noleggio ON noleggio.id_assicurazione_pagante = anag_assicurazioni.id
) AS noleggio ON noleggio.id_veicolo = veicoli_contratti.id
) AS noleggio ON noleggio.id_convenzionato = anag_convenzionati.id;
I need to join the resulting table with moduli_ocr table in this way:
SELECT
noleggio.*
FROM
(//query//) AS noleggio
LEFT JOIN
moduli_ocr ON moduli_ocr.id_noleggio = noleggio.id;
Where //query// is the code above.
The error I got (running the query in MySQL Workbench is:
Error Code: 1054. Unknown column 'noleggio.id' in 'on clause'
BTW I'm not sure if I have to use RIGHT or LEFT join but I will check this once the query is properly 'running'.
Best regards.
It seems that you assign idnoleggio alias to the field "id". Try joining on
moduli_ocr.id_noleggio = noleggio.idnoleggio;
I had a query which was working just fine:
#schedule = Schedule.find(params[:id])
#schedule_tasks = ScheduleTask.select("s.*, t.*, t.*, d.*, st.*").from("schedule_tasks st").
joins("left join schedules s ON s.id = st.schedule_id").
joins("left join tasks t ON t.id = st.task_id").
joins("right join days d ON d.id = st.day_id").
order("d.number, t.name").
group_by{|d| d.number}
I had to refine my search to only schedule_tasks with a specific schedule_id, so I edited the second line to:
joins("left join schedules s ON s.id = st.schedule_id AND s.id = ?", #schedule.id).
This has cause the following error:
unknown class: Fixnum
The error goes away if I take out the group_by - but I need that, and I have tried hard coding in the number instead of #schedule.id and that does not work either, a google search does not reveal a lot of details on this error.
For anyone coming here from Google, I used plain string interpolation to fix this issue. This method is vulnerable to SQL Injection, so make sure you type check your variables before using them.
In this case I would do
#schedule_id = #schedule.id
.
.
.
joins("left join schedules s ON s.id = st.schedule_id AND s.id = #{#schedule_id}")
Rather than following learning_to_swim's answer, which as noted is at risk of SQL injection, couldn't you cast your #schedule_id to a string?
#tasks = ScheduleTask.joins("left join [...] s.id = ?", #schedule.id.to_s)
select m1.id, m1.status, at.view_data, at.view_graph, ta.tag_string
from
access_tbl at, image_campaign_tbl m1
RIGHT JOIN
(select
GROUP_CONCAT(t.name) as tag_string , c.image_campaign_id
from campaign_tags_tbl c,tag_tbl t
where c.tag_id=t.id
$tag_q
group by c.image_campaign_id
) as ta
ON ta.image_campaign_id=m1.id
where
m1.client_id =$client_id
and m1.client_id = at.client_id
$prev_filter
limit $start,$end;
Error message:
in LOGS: DBD::mysql::db selectall_arrayref failed: Unknown column 't.name' in 'where clause' at /home/sakthi/rtads/Project/pm/Image/UI.pm line 2536.**
In Perl Module, I'm passing the same value of $tag_q to the $prev_filter to get the Pagination of filter based on TAGS values in the next page
if ( $prev_filter eq '' ) {
$prev_filter =
$search_clist_q . ' '
. $tag_q . ' '
}
From the error msg, I got the error which I'm doing. Since I'm trying to access the table of subquery in the main query, this error is happening.
So I want to know how to access the tag_string(or)t.name outside the subquery.
First of all, i suggest you to avoid use of old school syntax for jointures (FROM table1, table2,... WHERE table1.column1 = table2.column2 AND ...).
Here is the query that seems to return what you're looking for:
SELECT IC.id
,IC.status
,A.view_data
,A.view_graph
,TA.tag_string
FROM access_tbl A
INNER JOIN image_campaign_tbl IC ON IC.client_id = A.client_id
AND IC.client_id = $client_id
RIGHT JOIN (SELECT CT.image_campaign_id
,GROUP_CONCAT(T.name) AS [tag_string]
FROM campaign_tags_tbl CT
INNER JOIN tag_tbl T ON T.id = CT.tag_id
GROUP BY CT.image_campaign_id) TA ON TA.image_campaign_id = IC.id
WHERE <Your filters here>
LIMIT $start, $end
Hope this will help you.
I'm attempting to write a query that I know is compatible with MySQL to MS Access. This is a programming assignment, so I'm not expecting an answer straight up given to me, but I don't know MS Access' version of SQL well enough. I wrote the MySQL myself, and tested it to be working. That's when I realized that the query needed to work for MS Access instead. So here is the known code:
SELECT `D`.`RENT_NUM`,
`R`.`RENT_DATE`,
`D`.`VID_NUM`,
`M`.`MOVIE_TITLE`,
`D`.`DETAIL_DUEDATE`,
`D`.`DETAIL_RETURNDATE`,
`D`.`DETAIL_FEE`,
`D`.`DETAIL_RETURNDATE` - `D`.`DETAIL_DUEDATE` AS `DAYS_LATE`
FROM `detailrental` AS `D`
JOIN `rental` AS `R` ON `D`.`RENT_NUM` = `R`.`RENT_NUM`
JOIN `video` AS `V` ON `D`.`VID_NUM` = `V`.`VID_NUM`
JOIN `movie` AS `M` ON `V`.`MOVIE_NUM` = `M`.`MOVIE_NUM`
WHERE `D`.`DETAIL_RETURNDATE` - `D`.`DETAIL_DUEDATE` > 0
ORDER BY `R`.`RENT_NUM`, `M`.`MOVIE_TITLE`;
I've been attempting to convert to MS Access SQL, but I still don't get it. Here is the most recent attempt.
SELECT [D].[RENT_NUM],
[R].[RENT_DATE],
[D].[VID_NUM],
[M].[MOVIE_TITLE],
[D].[DETAIL_DUEDATE],
[D].[DETAIL_RETURNDATE],
[D].[DETAIL_FEE],
[D].[DETAIL_RETURNDATE] - [D].[DETAIL_DUEDATE] AS [DAYS_LATE]
FROM [DETAILRENTAL] AS [D] INNER JOIN
(
[RENTAL] AS [R] INNER JOIN
(
[VIDEO] AS [V] INNER JOIN [MOVIE] AS [M] ON [V].[MOVIE_NUM] = [M].[MOVIE_NUM]
) ON [D].[VID_NUM] = [V].[VID_NUM]
) ON [D].[RENT_NUM] = [R].[RENT_NUM]
WHERE [D].[DETAIL_RETURNDATE] - [D].[DETAIL_DUEDATE] > 0
ORDER BY [R].[RENT_NUM], [M].[MOVIE_TITLE];
The error I receive is Syntax error in JOIN operation. I know what that means, but I don't know MS Access' SQL well enough to spot the error.
It has been a while since I had to write any access query, so I just went with syntax described by official documentation http://msdn.microsoft.com/en-us/library/office/bb208854(v=office.12).aspx. Figured out it had syntax error in it. So to make query work you have to wrap JOIN with parenthesis. But each ON statement still needs to be inside each set of parenthesis not on outside. This should do the trick.
SELECT [D].[RENT_NUM]
,[R].[RENT_DATE]
,[D].[VID_NUM]
,[M].[MOVIE_TITLE]
,[D].[DETAIL_DUEDATE]
,[D].[DETAIL_RETURNDATE]
,[D].[DETAIL_FEE]
,[D].[DETAIL_RETURNDATE] - [D].[DETAIL_DUEDATE] AS [DAYS_LATE]
FROM (
(
(
[detailrental] AS [D] )
INNER JOIN [rental] AS [R]
ON [D].[RENT_NUM] = [R].[RENT_NUM] )
INNER JOIN [video] AS [V]
ON D.VID_NUM = [V].[VID_NUM] )
INNER JOIN [movie] AS [M]
ON [V].[MOVIE_NUM] = [M].[MOVIE_NUM]
WHERE [D].[DETAIL_RETURNDATE] - [D].[DETAIL_DUEDATE] > 0
ORDER BY [R].[RENT_NUM]
,[M].[MOVIE_TITLE];
Since we know that the problem is with the JOINs let's start from the innermost set of parentheses and work outwards:
[VIDEO] AS [V]
INNER JOIN
[MOVIE] AS [M]
ON [V].[MOVIE_NUM] = [M].[MOVIE_NUM]
That looks fine. Let's move out one level:
[RENTAL] AS [R] INNER JOIN
(
[VIDEO] AS [V]
INNER JOIN
[MOVIE] AS [M]
ON [V].[MOVIE_NUM] = [M].[MOVIE_NUM]
)
ON [D].[VID_NUM] = [V].[VID_NUM]
This JOIN won't work. Can you see why?