i got this error:
for the right syntax to use near 'INNER JOIN oferta B ON A.oferta_id_oferta = B.id_oferta AND B.oferta = "design' at line 4
i can't make a inner join inside a where clause ? or exists other problem with this query ?
UPDATE `oferta_has_tags` A
SET fraccao = "1/7"
WHERE (
INNER JOIN oferta B
ON A.oferta_id_oferta = B.id_oferta
AND B.oferta = "designer"
AND B.estado = 0)
Express it as a simple IN:
UPDATE oferta_has_tags
SET fraccao = '1/7'
WHERE oferta_id_oferta IN (
SELECT id_oferta
FROM oferta
WHERE oferta = 'designer'
AND estado = 0)
Also, changed double quotes (") to single quotes (') - using double quotes will cause an error
The query is wrong. It must have SELECT and FROM clauses:
It must be something like this:
UPDATE oferta_has_tags A
SET fraccao = "1/7"
WHERE id = ( SELECT id FROM yourtable WHERE something = somevalue )
Make sure that the subquery should return exactly 1 value. If you want to update multiple records using above query, replace "=" with "IN". Like this:
UPDATE oferta_has_tags A
SET fraccao = "1/7"
WHERE id IN ( SELECT id FROM yourtable WHERE something = somevalue )
Hope it helps...
Related
I keep getting a syntax error on line 3 in my "FROM( SELECT". I can't seem to figure out what might be causing it.
UPDATE lab_orders_lab_confirmationresults_c t
SET lab_orders_confirmationresultslab_confirmationresults_ida = foo.`1ID`
FROM(
SELECT x.id as '1ID', y.id as '2ID'
FROM lab_orders x
INNER JOIN lab_confirmationresults y ON x.orderid = y.orderid
)foo
WHERE t.lab_orders_confirmationresultslab_confirmationresults_ida = 'undefined'
AND t.lab_orders_confirmationresultslab_confirmationresults_idb = foo.`2ID`
UPDATE ... FROM ... isn't valid syntax. The closest you could get is
UPDATE table
SET a_column =
(SELECT one_column
FROM another_table
WHERE some_condition
LIMIT 1)
Note that the SELECT must return exactly one row of one column width for this to work.
I'm trying to search only the dirname from full path using this queries.
SELECT
`file_name` FROM `tbl_files` where SUBSTR(`file_path`,
LOCATE('/',`file_path`)+1,
(CHAR_LENGTH(`file_path`) - LOCATE('/',REVERSE(`file_path`)) - LOCATE('/',`file_path`))) =
(Select `source_path` from `tbl_transcode_folder` where `trancode_folder_id` = 1 )
But it return me nothing. When i replace (Select source_path from tbl_transcode_folder where trancode_folder_id = 1 ) into it's result mnt/hd/1 like the queries below , It's response want i to but i dont want to do in that way.
SELECT
`file_name` FROM `tbl_files` where SUBSTR(`file_path`,
LOCATE('/',`file_path`)+1,
(CHAR_LENGTH(`file_path`) - LOCATE('/',REVERSE(`file_path`)) - LOCATE('/',`file_path`))) = `mnt/hd/1`
Right now your sub-query returns a random row from the table you need to define a relation between the tbl_transcode_folder table, you need to define a relation between the outer query and the sub-query to make them correlated
SELECT `file_name`
FROM `tbl_files`
where SUBSTR(`file_path`, LOCATE('/',`file_path`)+1
,(CHAR_LENGTH(`file_path`) - LOCATE('/',REVERSE(`file_path`))
- LOCATE('/',`file_path`)))
=(Select `source_path`
from `tbl_transcode_folder`
where `trancode_folder_id` = 1
AND `tbl_files`.`CommonColumn` = `tbl_transcode_folder`.`CommonColumn`)
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.
I'm trying to update a table based on 2 select subquery that will be multipied to produce the value for Harga column
here is my code :
UPDATE bahanmakanan
SET Harga = (SELECT HargaSatuan from detail_bahanmakanan
WHERE IDBahanMakanan = "BM01")* (SELECT jumlah from bahanmakanan
WHERE IDBahanMakanan = "BM01")
WHERE IDBahanMakanan = "BM01" ;
The error message return
Error Code: 1093. You can't specify target table 'bahanmakanan' for update in FROM clause
you can simply do this using JOIN,
UPDATE bahanmakanan a
INNER JOIN detail_bahanmakanan b
ON a.IDBahanMakanan = b.IDBahanMakanan
SET a.Harga = a.jumlah * b.HargaSatuan
WHERE a.IDBahanMakanan = 'BM01'
Please do backup first your database before executing the statement.
Try this:
UPDATE bahanmakanan as t1
JOIN detail_bahanmakanan as t2 USING(IDBahanMakanan)
SET t1.Harga = t2.HargaSatuan * t1.jumlah
WHERE IDBahanMakanan = "BM01";
code = 00000000005555
2nd option code = 00000000000555
hi i am try to find out same function like ltrim() of php
SELECT * FROM db1.stock JOIN db2.prodinfo ON replace(db2.prodinfo.code,0000000000,'') = replace(db1.stock.code,0000000000,'') WHERE db1.stock.InvNo ='12' and db2.prodinfo.Cat = 'super'
i rum this temporary. becuse zero might be increase and decrease i
example above. i am just want to remove zero in this query
thanks
try by casting it into numeric,
SELECT *
FROM db1.stock JOIN db2.prodinfo ON
CAST(db2.prodinfo.code AS SIGNED) = CAST(db1.stock.code AS SIGNED)
WHERE db1.stock.InvNo ='12' and db2.prodinfo.Cat = 'super'
or
SELECT *
FROM db1.stock JOIN db2.prodinfo ON
CAST(db2.prodinfo.code AS DECIMAL(15,0)) = CAST(db1.stock.code AS AS DECIMAL(15,0))
WHERE db1.stock.InvNo ='12' and db2.prodinfo.Cat = 'super'