Hello i'm trying to make an update with a select statement.
Here is my code
update recolha_hrs_2014 r set r.state = 'porval' from (select e.sigla
from dgrhe_entidade e) where r.state = 'finalizado' and r.qzp = '10'
and e.sigla = '145014'
However it gives me an error.
ERROR: subquery in FROM must have an alias
LINE 3: from (select e.sigla from dgrhe_entidade e)
Any suggestion. What am i doing wrong?
Hope you can help me
Thanks,
Try this:
update r
set set r.state = 'porval'
from recolha_hrs_2014 r
inner join dgrhe_entidade e on e.??? = r.????
where r.state = 'finalizado' and r.qzp = '10' and e.sigla = '145014'
I'm not sure which field(s) in dgrhe_entidade map to recolha_hrs_2014, but that's what needs to go in: "e.??? = r.????"
Related
Having a problem with the plugin DMSF in redmine I have found a link with a SQL query that could fix the issue, however I am using PostgreSQL and that query returns a syntax error directly on f.project_id.
The MySQL query is:
update dmsf_files f
set f.project_id = (select d.project_id from dmsf_folders d where d.id = f.dmsf_folder_id and d.system = 1)
where (select dmsf_folders.system from dmsf_folders where dmsf_folders.id = f.dmsf_folder_id) = 1;
What should be the PostgreSQL equivalent ?
I have found some online Database syntax translator but unfortunately with no success at all.
Remove the alias from the left side of the SET clause:
update dmsf_files f
set project_id = (select d.project_id from dmsf_folders d
where d.id = f.dmsf_folder_id and d.system = 1)
where (select dmsf_folders.system from dmsf_folders
where dmsf_folders.id = f.dmsf_folder_id) = 1;
I want to DELETE data OR UPDATE data in MYSQL. such that if column message_deleted_by is found in a string IN() then the query should delete rows where the WHERE clause(filtering) is true ELSE the query should update message_table column message_deleted_by with some data ....ALL IN THE SAME QUERY
if this can be achieved please help.
I'v tried and tried but it output errors.
$token = mysqli_real_escape_string($dbc_conn,encode64(getsecreteToken($_POST["token"])));
$mid = mysqli_real_escape_string($dbc_conn,$_POST["mid"]);
$rid = mysqli_real_escape_string($dbc_conn,$_POST["rid"]);
$sid = mysqli_real_escape_string($dbc_conn,$_POST["sid"]);
$group = implode(",",array($rid,$sid));
$IsLoggIn = '2';
$SQL = "
IF(
SELECT message_deleted_by AS mdb FROM $message_tatable
WHERE (
m.sender_id='$IsLoggIn' AND m.recipient_id='$rid'
) AND
m.token='$token' AND m.id='$mid'
) mdb IN($group) THEN
DELETE m,mf
FROM $message_tatable m
LEFT JOIN $message_files_tb mf ON
m.token=mf.token
WHERE (
m.sender_id='$IsLoggIn' AND m.recipient_id='$rid'
) AND
m.token='$token' AND m.id='$mid';
ELSE
UPDATE $message_tatable SET message_deleted_by='$IsLoggIn'
WHERE (
m.sender_id='$IsLoggIn' AND m.recipient_id='$rid'
) AND
m.token='$token' AND m.id='$mid';
END IF;
";
//QUERY database
$query = mysqli_query($dbc_conn,$SQL);
die(mysqli_error($dbc_conn));
Try this,
UPDATE $message_tatable m
LEFT JOIN $message_files_tb mf
ON m.token=mf.token
SET m=NULL,
mf=NULL
WHERE m OR mf=SELECT message_deleted_by FROM $message_tatable IN($group)
AND m.sender_id='$IsLoggIn' AND m.recipient_id='$rid'
AND m.token='$token' AND m.id='$mid'
I have the following SQL statement:
UPDATE tbl_Invoices
SET tbl_Invoices.Base = tbl_Bases.BasePrice
FROM tbl_Invoices
INNER JOIN tbl_Bases ON tbl_Bases.ProductNumber = tbl_Invoices.ProductNumber
AND tbl_Bases.ChangeOrderID = tbl_Invoices.ChangeOrderID
AND tbl_Bases.CustomerName = 'VALEO'
AND tbl_Bases.CountryCode = 'FR'
AND tbl_Bases.ContractYear = 0
Access keep telling me I have a syntax error (missing operator)
This drives me nuts. Can someone tell me what's wrong?
UPDATE ... FROM doesn't exist in Access SQL, here you do it like this:
UPDATE tbl_Invoices
INNER JOIN tbl_Bases ON tbl_Bases.ProductNumber = tbl_Invoices.ProductNumber
AND tbl_Bases.ChangeOrderID = tbl_Invoices.ChangeOrderID
AND tbl_Bases.CustomerName = 'VALEO'
AND tbl_Bases.CountryCode = 'FR'
AND tbl_Bases.ContractYear = 0
SET tbl_Invoices.Base = tbl_Bases.BasePrice
Thanks a lot.
I still have an error as the = 'VALEO' etc... are not allowed in Join but this is working if moved to a where clause:
UPDATE tbl_Invoices
INNER JOIN tbl_Bases ON tbl_Bases.ProductNumber = tbl_Invoices.ProductNumber
AND tbl_Bases.ChangeOrderID = tbl_Invoices.ChangeOrderID
SET tbl_Invoices.Base = tbl_Bases.BasePrice
WHERE tbl_Bases.CustomerName = 'VALEO'
AND tbl_Bases.CountryCode = 'FR'
AND tbl_Bases.ContractYear = 0
I need to update a table and this is my sql code so far but i'm getting the following error message:
Line 30: Incorrect syntax near ')'.
UPDATE dbo.Part
SET SupplierShortName = NationalSupplier.ShortName,
SupplierLongName = NationalSupplier.LongName
SELECT *
FROM dbo.Part
JOIN dbo.NationalSupplier
ON Part.SupplierNumber = NationalSupplier.Number
AND (ISNULL(Part.SupplierShortName,'') <> ISNULL(NationalSupplier.ShortName,'')
OR ISNULL(Part.SupplierLongName,'') <> ISNULL(NationalSupplier.LongName,''))
LEFT OUTER JOIN dbo.NationalPart
ON Part.NationalPartID = NationalPart.NationalPartID
WHERE Part.DWCreationEntityID = 1
AND NationalPart.NationalPartID is NULL
Thanks in advance for any valuable tips !
Try this:
UPDATE dbo.Part
SET SupplierShortName = NationalSupplier.ShortName,
SupplierLongName = NationalSupplier.LongName
FROM dbo.Part
JOIN dbo.NationalSupplier
ON Part.SupplierNumber = NationalSupplier.Number
AND (ISNULL(Part.SupplierShortName,'') <> ISNULL(NationalSupplier.ShortName,'')
OR ISNULL(Part.SupplierLongName,'') <> ISNULL(NationalSupplier.LongName,''))
LEFT OUTER JOIN dbo.NationalPart
ON Part.NationalPartID = NationalPart.NationalPartID
WHERE Part.DWCreationEntityID = 1
AND NationalPart.NationalPartID is NULL
You should alias the table names to make things concise.
Can anyone tell me what is wrong with this Query ?
UPDATE
violetta.navi__stop
SET
violetta.navi__stop.endHour = VB.endHour
FROM
violetta.navi__stop AS V
INNER JOIN
violetta_back.navi__stop AS VB
ON V.code = VB.code
This code sample works for me on my database:
SELECT
V.code, V.endHour
FROM
violetta.navi__stop AS V
UNIQUE
violetta_back.navi__stop AS VB
ON V.code = VB.code
Try this instead:
UPDATE
violetta.navi__stop v
INNER JOIN
violetta_back.navi__stop AS VB
ON V.code = VB.code
SET
v.endHour = VB.endHour