Empty record MySQL, how find? - mysql

Please help to fix this error:
SELECT SQL_CACHE p.user_id, p.project_id, p.cid, p.project_title, p.additional_info, p.buynow_price, p.date_added, p.highlite, p.project_details, p.views, p.bids, p.currentprice, p.currencyid, p.buynow, p.filtered_auctiontype, p.buynow_purchases, p.date_starts, p.buynow_qty_lot, p.items_in_lot, UNIX_TIMESTAMP(p.date_end) - UNIX_TIMESTAMP('2017-08-05 18:14:50') AS mytime, UNIX_TIMESTAMP(p.date_starts) - UNIX_TIMESTAMP('2017-08-05 18:14:50') AS starttime, p.donation, p.filter_budget, p.reserve, p.project_state, p.bid_details, p.filter_escrow, p.filter_gateway, p.charityid, p.jobs_price
          FROM xxx_projects AS p
          LEFT JOIN xxx_users u ON(p.user_id = u.user_id)
          WHERE p.visible = '1'
          AND p.status = 'open'
          AND p.project_state = 'product'
          AND u.status = 'active'
          AND p.project_id IN (88414723, 5043541, 98506492, 36121136, 84626697, , 4408122, 49183201, 56318356, 89533629, 16433073, 70069844, 6242686, 8745727, 10816822, 8745727, 27902749, 41807041, 61556755, 46837725, 38855144, 69491982, 27240408, 20425411)
          
MySQL Error  : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right
syntax to use near ' 4408122, 49183201, 56318356, 89533629, 16433073,
70069844, 6242686, 8745727, 10' at line 8
I think in db is empty record but i can'f find it...

You have a double comma in 84626697, , 4408122. Just remove one comma (i.e., make it 84626697, 4408122) and you should be good to go.

Related

MySQL : error in your SQL syntax | LIMIT 0, 25

I dont understand this error, guys please help me. why I am getting this error..
Is there something wrong in my query?
this is the error..
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'LIMIT 0, 25' at line 7
and this is my query:
SELECT
equivalent
FROM
tb_student_record
INNER JOIN
tb_student ON tb_student_record.stud_id = tb_student.stud_id
WHERE
tb_student_record.instructor_id = 'INST-20131296'
AND tb_student_record.criteria_id = '1'
AND tb_student_record.class_record_id = '1'
AND (CONCAT(stud_fname, ' ', stud_lname) = 'Jeffrey Oliveras'
AND tb_student_record.term = 'Prelim'
you are missing closing paranthesis at concat function
SELECT equivalent FROM tb_student_record INNER JOIN tb_student ON tb_student_record.stud_id=tb_student.stud_id
WHERE tb_student_record.instructor_id = 'INST-20131296'
AND tb_student_record.criteria_id = '1'
AND tb_student_record.class_record_id = '1'
AND (CONCAT(stud_fname, ' ', stud_lname) = 'Jeffrey Oliveras' )
AND tb_student_record.term = 'Prelim'
It seems that your query have problem at the end:

SQL error #1064 when nesting a SELECT MAX in a LEFT JOIN

Please let me know why I get an error on the following SQL (I am using a MySQL database) and how to rectify it:
SELECT at_award_description.ad_id,
at_award_description.ad_detail,
at_award_description.ad_archived_date,
a.cad_id,
a.cad_task_completion_date
FROM at_award_description
LEFT JOIN at_cub_award_date AS a ON ((at_award_description.ad_id = a.ad_id)
AND (a.ca_id = 37)
AND a.cad_task_completion_date = (SELECT MAX(b.cad_task_completion_date)
FROM at_cub_award_date AS b
WHERE a.ca_id = b.ca_id AND a.ad_id = b.ad_id
)
)
WHERE at_award_description.aw_id = 5
ORDER BY at_award_description.ad_order;
I broke the SQL down to ensure each part worked.
SELECT MAX(b.cad_task_completion_date)
FROM at_cub_award_date AS b
And
SELECT at_award_description.ad_id,
at_award_description.ad_detail,
at_award_description.ad_archived_date,
a.cad_id,
a.cad_task_completion_date
FROM at_award_description
LEFT JOIN at_cub_award_date AS a ON ((at_award_description.ad_id = a.ad_id)
AND (a.ca_id = 37)
)
WHERE at_award_description.aw_id = 5
ORDER BY at_award_description.ad_order;
Each of these work on their own. When I combine them I get the following error:
Error
SQL query:
LIMIT 0, 25
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 25' at line 1
Regards,
Glyn
EDIT
#Barmar came up with the solution to remove the ";" at the end when testing. However, the result was not what I expected so I ended up changing this to:
SELECT at_award_description.ad_id,
at_award_description.aw_id,
at_award_description.ad_group,
at_award_description.ad_detail,
at_award_description.ad_start_date,
at_award_description.ad_archived_date,
MAX(at_cub_award_date.cad_task_completion_date)
FROM at_award_description
LEFT JOIN at_cub_award_date ON ((at_award_description.ad_id = at_cub_award_date.ad_id)
AND (at_cub_award_date.ca_id = 37))
WHERE at_award_description.aw_id = 5
GROUP BY at_award_description.ad_group
ORDER BY at_award_description.ad_order, at_award_description.ad_group

Is it valid to use DISTINCT two times in a single query

I'm getting this following error:
MYSQL ERROR
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'DISTINCT R.roomtype as roomtype , I1.meal_plan as
mealplan , I1.`bed_t' at line 3
My Code is
SELECT
DISTINCT H.`hotelname` as `hotelname` ,
DISTINCT R.`roomtype` as `roomtype` ,
I1.`meal_plan` as `mealplan` ,
I1.`bed_type` as `bedtype` ,
I1.`roomrate` as `roomrate` ,
I1.`pax` as `pax` ,
I1.`childrate` as `childrate` ,
I1.`childrate1` as `childrate1` ,
I1.`childrate2` as `childrate2` ,
I1.`childrate3` as `childrate3` ,
P.`profitmarkup_type` as `profit_type` ,
P.`applyprofit_val_room` as `applyprofit_val_room` ,
P.`applyprofit_val_bed` as `applyprofit_val_bed`
FROM `hoteldetails` H
INNER JOIN `roomdetails` R
on H.`hotelname` = R.`hotelname`
INNER JOIN `inventorypolicy` I1
on I1.`hotel_name` = H.`hotelname`
AND I1.`room_plan` = R.`roomtype`
AND I1.`bed_type`=R.`bedtype`
AND I1.`meal_plan`=R.`mealplan`
AND I1.`suppliername`=H.`supplier`
INNER JOIN `profitmarkup` P
on P.`hotel_name` = H.`hotelname`
AND P.`suppliername` = H.`supplier`
WHERE H.`active`='1'
AND H.`country`='MAL'
AND H.`city`='KL'
AND H.`show2web`='1'
AND H.`expiry_date` >= 11/09/2014
AND I1.`inventory_status`='1'
AND P.`markup_status` = '1'
AND 20140911 BETWEEN ((I1.`date1`)+(I1.`month1`*100)+(I1.`year1`*10000)) AND ((I1.`date2`)+(I1.`month2`*100)+(I1.`year2`*10000))
AND 20140911 BETWEEN ((P.`date1`)+(P.`month1`*100)+(P.`year1`*10000)) AND ((P.`date2`)+(P.`month2`*100)+(P.`year2`*10000))
I dont know how to fix this. Any help is greatly appreciated.
As you can learn from the documentation of the SELECT MySQL statement, DISTINCT can be placed before any field or expression to be selected. This automatically forces a single instance of it in a query.
And somewhere down the road there is a sentence that says everything:
DISTINCTROW is a synonym for DISTINCT.

SQL UPDATE with SELECT Issue. SQL syntax error

I have a problem with my SQL. I would like to use a select to make an update, but so far I haven't been able to acomplish it. I would really apreciate if anyone could please help me. I'm quite new at MySQL. THe query in question is this:
UPDATE
pac
SET
pac.pac_spc_id = dtn_atual.spc_id
FROM
pac_paciente pac
INNER JOIN ( SELECT
dtn.dtn_pac_id,
spc_id
FROM `pac_destino` dtn
INNER JOIN ( select
des.dtn_pac_id,
MAX(CONCAT(des.dtn_data, des.dtn_seq)) AS datamax
FROM pac_destino des
GROUP BY des.`dtn_pac_id`
) AS d1 ON d1.dtn_pac_id = dtn.dtn_pac_id
AND d1.datamax = CONCAT(dtn.dtn_data, dtn.dtn_seq)
LEFT JOIN pac_classdestino c1 ON c1.cdo_id = dtn.dtn_cdo_id
LEFT JOIN pac_statuspaciente spc ON spc.spc_id = c1.cdo_spc_id
) AS dtn_atual on dtn_atual.dtn_pac_id = pac.`pac_id`
The error generated is
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near 'FROM pac_paciente pac INNER JOIN ( SELECT
dtn.dtn_pac_id, spc_id
' at line 5

mysql - using reserved names as column name

I am trying to run this query but doesn't run
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id = '1'pd.id = ng.post_id
ORDER BY ng.order
and getting error
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'pd.id = ng.post_id ORDER BY ng.order' at line 1
i've tried `ng.order` and `ng`.`order` but still cant seem to get it to run.
Any help is much appreciated
I think you're just missing an and:
AND ng.parent_id = '1'pd.id = ng.post_id
should probably be:
AND ng.parent_id = '1'
AND pd.id = ng.post_id
Or better, put the join condition in the join (and don't quote your numbers unless they really are strings):
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng join `ecom_page_data` AS pd on ng.post_id = pd.id
WHERE ng.cluster_key = 'primary'
AND ng.tab = 0 -- Leave the quotes on if tab is a string
AND ng.parent_id = 1 -- Leave the quotes on if parent_id is a string
ORDER BY ng.order
try
ng.order
if i could get backticks to show in this editor, then they would be there, but it seems to remove them
backticks are used to escape reserved words and spaces in column names etc
Change your query to (you have a ' misplaced)
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id = '1' AND pd.id = ng.post_id
ORDER BY ng.order
OR
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id = 1 AND pd.id = ng.post_id
ORDER BY ng.order