i've been having an error with this query and i'm not sure how to fix it. this query is supposed to filter occupations stored in my database to match the volunteer's occupation. please help me fix my query. all the names in this query are correctly spelled, i double checked all the spellings before writing the query here.
the error says "#1064 - 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 'SELECT (SELECT count(*) FROM occupation_event WHERE event_id='8' AND occupationN' at line 1"
SELECT
*
FROM
volunteer_details
WHERE
user_id=73
AND
volunteer_occupation in (
SELECT
occupationName
FROM
occupation_event
WHERE
event_id=8
OR SELECT (
SELECT
count(*)
FROM
occupation_event
WHERE
event_id='8'
AND
occupationName = 'No Occupation Required') > 0 AS need
)
I think the error is the as need at the end. I would write this as:
SELECT vd.*
FROM volunteer_details vd
WHERE user_id = 73 AND
(vd.volunteer_occupation in (SELECT oe.occupationName FROM occupation_event oe WHERE oe event_id = 8) or
exists (select 1 from occupation_event oe where event_id = 8 and oe.occupationName = 'No Occupation Required')
);
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.
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
This mysql query runs just fine independently. But when I use this query to create a view then Error Code: 1064 message appears in sql yog. Please identify the reason of this error.
CREATE
VIEW `databaseName`.`viewName`
AS
((SELECT
`tblgrn`.`InitialLabNo`
, `invlabtes`.`Code` AS LabNo
, `invlabmaterial`.`Description` AS material
, `invlabtessubtable`.`SrNo`
, `invlabtessubtable`.`Result`
,COALESCE(NULL, 'Verified') AS TYPE
, `tblgrn`.`Comp_Code`
, `tblgrn`.`Unit_Code`
, `tblgrn`.`UserId`
FROM
`tblgrn`
INNER JOIN `invlabtes`
ON (`tblgrn`.`InitialLabNo` = `invlabtes`.`Code`)
INNER JOIN `invlabtessubtable`
ON (`invlabtes`.`Code` = `invlabtessubtable`.`Code`)
INNER JOIN `invlabmaterial`
ON (`invlabtessubtable`.`TestCode` = `invlabmaterial`.`Code`))
UNION
(SELECT
`tblgrn`.`InitialLabNo`
, `invlabtesscale`.`Code` AS LabNo
, `invlabmaterial`.`Description`
, `invlabscalesubtable`.`SrNo`
, `invlabscalesubtable`.`Result`
,COALESCE(NULL, 'Running') AS TYPE
, `tblgrn`.`Comp_Code`
, `tblgrn`.`Unit_Code`
, `tblgrn`.`UserId`
FROM
`tblgrn`
INNER JOIN `invlabtesscale`
ON (`tblgrn`.`InitialLabNo` = `invlabtesscale`.`IniLabNo`)
INNER JOIN `invlabscalesubtable`
ON (`invlabtesscale`.`Code` = `invlabscalesubtable`.`Code`)
INNER JOIN `invlabmaterial`
ON (`invlabscalesubtable`.`TestCode` = `invlabmaterial`.`Code`)));
this is the error message:
Error Code: 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 'UNION
SELECT
tblgrn.InitialLabNo
, invlabtesscale.Code AS LabNo' at line 22
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0.018 sec
Remove the bracket between UNION and SELECT.
UNION
(SELECT
should be
UNION
SELECT
You may need to remove the closing bracket too.
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