Update field x from second join error - mysql

I want to update a.instit but instead of result i got an error 1064
UPDATE a
SET a.instit = c.bezeichnung
FROM kunde AS a
INNER JOIN bestellte_artikel AS b
ON a.idkunde = b.idkunde
INNER JOIN artikel AS c
ON b.idartikel = c.idartikel
where 1
Thank You in Advance.

You're using SQL-Server syntax, try this :
UPDATE kunde a
INNER JOIN bestellte_artikel b
ON a.idkunde = b.idkunde
INNER JOIN artikel c
ON b.idartikel = c.idartikel
SET a.instit = c.bezeichnung
where 1

Related

Join two SQL tables from diferent queries

I'm trying to join these two queries. Can anyone help?
Query 1 -
SELECT provas.id, disciplinas.disciplina, disciplinas.grupo,salas.sala
FROM provas, disciplinas, horarios, salas
WHERE provas.id = provas.id AND provas.id_disciplina = disciplinas.id AND provas.id_horario = horarios.id AND provas.id_sala = salas.id AND provas.id_horario JOIN horarios ON ;
Query 2 -
SELECT dias.dia, meses.nome, horas.hora, minutos.minuto
FROM horarios, meses, dias, horas, minutos
WHERE horarios.id = horarios.id AND horarios.id_dia = dias.id AND horarios.id_hora = horas.id AND horarios.id_mes = meses.id AND horarios.id_minuto = minutos.id;
Main table
Second Main table
I want to associate the "provas" table with the "horario" but the horario table has more foreign keys
provas = exams
horarios = scheudule
I want to join the shedule on the exams table, but the sheudule have more foreign keys for tables "days", "months", "hours" and "minutes"
All involved tables
You can try the following query. I didn't run this to make sure no syntax errors. But you can see the concept. You can join with a result set of a second query as shown below. I suggest you to consider the joins in your original query again. You may change the joins in my answer as it fits for your purpose.
SELECT ps.id, das.disciplina, das.grupo,s.sala
FROM provas ps
inner join disciplinas das on ps.id_disciplina = das.id
inner join horarios hs on ps.id_horario = hs.id
inner join salas s on ps.id_sala = s.id
inner join (
SELECT d.dia, ms.nome, h.hora, m.minuto, hs.id hsid
FROM horarios hs
inner join meses ms on hs.id_mes = ms.id
inner join dias d on hs.id_dia = d.id
inner join horas h on hs.id_hora = h.id
inner join minutos m on hs.id_minuto = m.id) zz on ps.id_horario = zz.hsid
My solution (I prefer this way):
SELECT provas.id, disciplinas.disciplina, disciplinas.grupo,salas.sala ,dias.dia, meses.nome, horas.hora, minutos.minuto
FROM provas, disciplinas, horarios, salas, meses, dias, horas, minutos
WHERE provas.id = provas.id AND provas.id_disciplina = disciplinas.id AND provas.id_horario = horarios.id AND provas.id_sala = salas.id AND provas.id_horario AND horarios.id_dia = dias.id AND horarios.id_hora = horas.id AND horarios.id_mes = meses.id AND horarios.id_minuto = minutos.id;

Select Insert and Update in One Query MySql

I am trying to update one table from 3 tables which is working fine, but i want to update a table from 3 after i insert data in 4th table, here what i am doing
INSERT INTO relation_table(cid,pid,liid,lnid,lgid,l_key)
SELECT a.cid,
a.pid,
b.liid,
c.lnid,
d.lgid,
md5(CONCAT(a.cid, a.pid, a.lurl, c.lnid, d.lang))
FROM links a
INNER JOIN links_table b
ON a.lurl = b.lurl
INNER JOIN lname_table c
ON a.lname = c.lname
INNER JOIN lang_table d
ON a.lang = d.lang
where a.checked != "3" limit 2;
update links SET checked='3'
WHERE lid=a.lid
Last statement is not working for update
Please help ;)
Try this:
UPDATE links a
INNER JOIN links_table b ON a.lurl = b.lurl
INNER JOIN lname_table c ON a.lname = c.lname
INNER JOIN lang_table d ON a.lang = d.lang
SET a.checked='3'
WHERE a.checked != '3' LIMIT 2;

UPDATE table whith specific condition

I have 2 tables - products and product_categories.
These tables JOIN ON products.product_id = product_categories.product_id .
I want to UPDATE field published in table products which have condition product_categories.product_categories = 100 .
Try this
UPDATE bjvui_virtuemart_products as prod
INNER JOIN bjvui_virtuemart_product_categories as cat
ON prod.virtuemart_product_id =cat.virtuemart_product_id
SET prod.published ={value}
WHERE cat.virtuemart_category_id=100
Use UPDATE with JOIN
UPDATE TABLEA a
JOIN TABLEB b ON a.join_colA = b.join_colB
SET a.columnToUpdate = [something]
WHERE a.someColumn = [some_value]
For your case
UPDATE bjvui_virtuemart_products AS p
INNER JOIN bjvui_virtuemart_product_categories AS c ON
p.virtuemart_product_id = c.virtuemart_product_id
SET p.published = "your_value"
WHERE c.virtuemart_category_id = 100;

MySQL UPdate where INNER join

I would like to update a table based on reading a value in another table.
UPDATE contacts_cstm set ld_dt_crtd_c = '2014-06-11 12:26:17'
WHERE **id = 'b0bc2ccf-ddfe-81b1-a278-53ba8bd0a93f'** AND deleted=0
However id is a column in contacts table.
UPDATE contacts_cstm
INNER JOIN contacts ON contacts.whatever_column = contacts_cstm.whatever_column
set ld_dt_crtd_c = '2014-06-11 12:26:17' WHERE id = 'b0bc2ccf-ddfe-81b1-a278-53ba8bd0a93f' AND deleted=0
You can Try this example
UPDATE
Sales_Import
SET
Sales_Import.AccountNumber = RAN.AccountNumber
FROM
Sales_Import SI
INNER JOIN
RetrieveAccountNumber RAN
ON
SI.LeadID = RAN.LeadID
UPDATE
UPDATE contacts_cstm
SET ld_dt_crtd_c = '2014-06-11 12:26:17'
FROM contacts_cstm cc
INNER JOIN contacts c ON cc.id = c.id
WHERE cc.deleted = 0

How can I update filed value from a select with inner join?

I am trying to update a field value in a mysql database using a select query with inner join
I currently get
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 'AS cc WHERE cc.account_id = na.account_id' at line 5
UPDATE accounts AS na
SET na.pdm_id = (
SELECT cp.person_id FROM `temp_accounts` AS ta INNER JOIN call_managment_system.accounts AS a ON ta.company_code = a.company_code
INNER JOIN contact_personal AS cp ON cp.name = ta.FSM AND contact_link = 'PDM'
)
WHERE a.account_id = na.account_id
How can I fix this query to work? I want to update the field called pdm_id to set it equal to cp.person_id
Thanks
UPDATE accounts na
INNER JOIN call_managment_system.accounts a
ON a.account_id = na.account_id
INNER JOIN temp_accounts ta
ON ta.company_code = a.company_code
INNER JOIN contact_personal cp
ON cp.name = ta.FSM
SET na.pdm_id = cp.person_id
WHERE contact_link = 'PDM'