This question already has answers here:
Delete with Join in MySQL
(14 answers)
Closed 7 years ago.
I have the following statement below that is getting an error of 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 'c
JOIN campaignsFroms f ON f.id = c.id
JOIN campaignsRaw r ON r.' at line 2
What syntax am I missing?
Code:
DELETE
FROM campaigns c
JOIN campaignsFroms f ON f.id = c.id
JOIN campaignsRaw r ON r.id = c.id
JOIN campaignsSubjects s ON s.id = c.id
JOIN campaignIPTracking ip ON ip.id = c.id
JOIN campaignTracking ct ON ct.id = c.id
WHERE c.id = '1582'
DELETE c
FROM campaigns c
JOIN campaignsFroms f ON f.id = c.id
JOIN campaignsRaw r ON r.id = c.id
JOIN campaignsSubjects s ON s.id = c.id
JOIN campaignIPTracking ip ON ip.id = c.id
JOIN campaignTracking ct ON ct.id = c.id
WHERE c.id = '1582'
Related
i have query like this
select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
left join (select e.pict as pict from mst021 e
where e.line_number =
(select max(f.line_number) from mst021 f where f.mst020_id = a.id)
and e.mst020_id = a.id) j
but when i process this query,, error show :
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 '' at line 5
i'm trying to learn my sql because at oracle its not problme if g have subquery like that.thx
You're missing an ON statement to go with the rest of the join.
I've reformatted your query:
select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
left join (
SELECT e.pict as pict
FROM mst021 e
WHERE e.line_number =
(
SELECT max(f.line_number)
FROM mst021 f
WHERE f.mst020_id = a.id
)
AND e.mst020_id = a.id
) j
As you see, the last left join doesn't have an on clause, and the last and is misplaced. Also, in your inner most query (select max) you refer to the outermost query. This is not possible. You should probably rewrite the query, at least, I don't know what you are trying to do, so I can't correct it.
i have an answer. the error because i'm join the table at sub query and with outside subquery like this
select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
left join (select e.pict as pict from mst021 e
where e.line_number =
(select max(f.line_number) from mst021 f where f.mst020_id = a.id)
and **e.mst020_id = a.id**) j on j.mst021_id = a.id
so i change to this and thats successful
select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
left join (select e.pict as pict from mst021 e
where e.line_number =
(select max(f.line_number),g.mst021_id from mst021 f )) j on j.mst021_id = a.id
at my sql we can't join with table at outside subquery
I am trying to get the below query to delete all rows by id however the query is running fine but its not executing - no errors or rows effected. I have tripple checked all of the coloumn names in the tables and they are correct.
MYSQL:
DELETE c FROM campaigns c
JOIN campaignsFroms f ON f.campaign_id = c.id
JOIN campaignsRaw r ON r.campaignId = c.id
JOIN campaignsSubjects s ON s.campaign_id = c.id
WHERE c.id = 1582
I wonder if you want this:
DELETE c, f, r, s
FROM campaigns c LEFT JOIN
campaignsFroms f
ON f.campaign_id = c.id LEFT JOIN
campaignsRaw r
ON r.campaignId = c.id LEFT JOIN
campaignsSubjects s
ON s.campaign_id = c.id
WHERE c.id = 1582;
This will delete records from all the tables that are connected to the campaign. The LEFT JOIN is to ensure that the rows are not removed from consideration by the joins.
I have the following join below and I was wanting to know is there a better way to write it as I am getting Unknown table 'id' in MULTI DELETE and I cannot seem to pin point where.
Join:
$query = $dbConnection->prepare('
DELETE c.id, r.id, s.id,f.id,ip.id,ct.id
FROM campaigns c
JOIN campaignsFroms f ON f.id = c.id
JOIN campaignsRaw r ON r.id = c.id
JOIN campaignsSubjects s ON s.id = c.id
JOIN campaignIPTracking ip ON ip.id = c.id
JOIN campaignTracking ct ON ct.id = c.id
WHERE c.id = :campaign_id');
$query->execute(array(':campaign_id' => $campaign_id));
Your DELETE statement is incorrect. You should remove the fields.
DELETE
FROM campaigns c
JOIN campaignsFroms f ON f.id = c.id
JOIN campaignsRaw r ON r.id = c.id
JOIN campaignsSubjects s ON s.id = c.id
JOIN campaignIPTracking ip ON ip.id = c.id
JOIN campaignTracking ct ON ct.id = c.id
WHERE c.id = :campaign_id'
I got this error and I'm not sure how to work with it. Simple explanations would be much appreciated. Error:
Error Number: 1140
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
SELECT a.nim,b.nama_mahasiswa,c.j_sks,b.jurusan,b.kelas_program,e.status from tbl_dosen_wali a left join tbl_mahasiswa b on a.nim=b.nim left join (select k.nim,k.kd_jadwal,SUM(l.jum_sks) as j_sks from tbl_perwalian_detail k left join (select x.kd_jadwal, y.jum_sks from tbl_jadwal x left join tbl_mk y on x.kd_mk=y.kd_mk) as l on k.kd_jadwal=l.kd_jadwal) c on a.nim=c.nim left join tbl_perwalian_header e on a.nim=e.nim where a.kd_dosen='D001' group by a.nim
Filename: C:\xampp\htdocs\krs\siakad\system\database\DB_driver.php
Line Number: 330
Formatted Query:
SELECT a.nim,
b.nama_mahasiswa,
c.j_sks,
b.jurusan,
b.kelas_program,
e.status
FROM tbl_dosen_wali a
LEFT JOIN tbl_mahasiswa b
ON a.nim = b.nim
LEFT JOIN (SELECT k.nim,
k.kd_jadwal,
Sum(l.jum_sks) AS j_sks
FROM tbl_perwalian_detail k
LEFT JOIN (SELECT x.kd_jadwal,
y.jum_sks
FROM tbl_jadwal x
LEFT JOIN tbl_mk y
ON x.kd_mk = y.kd_mk) AS l
ON k.kd_jadwal = l.kd_jadwal) c
ON a.nim = c.nim
LEFT JOIN tbl_perwalian_header e
ON a.nim = e.nim
WHERE a.kd_dosen = 'D001'
GROUP BY a.nim
as the error said you need to use GROUP BY in your subquery.
try this
SELECT a.nim,
b.nama_mahasiswa,
c.j_sks,
b.jurusan,
b.kelas_program,
e.status
FROM tbl_dosen_wali a
LEFT JOIN tbl_mahasiswa b
ON a.nim = b.nim
LEFT JOIN (SELECT k.nim,
k.kd_jadwal,
Sum(l.jum_sks) AS j_sks
FROM tbl_perwalian_detail k
LEFT JOIN (SELECT x.kd_jadwal,
y.jum_sks
FROM tbl_jadwal x
LEFT JOIN tbl_mk y
ON x.kd_mk = y.kd_mk) AS l
ON k.kd_jadwal = l.kd_jadwal
GROUP BY k.nim
^^^^^^^^^^^^^^^^
) c
ON a.nim = c.nim
LEFT JOIN tbl_perwalian_header e
ON a.nim = e.nim
WHERE a.kd_dosen = 'D001'
GROUP BY a.nim
This question already has answers here:
Alternative to Intersect in MySQL
(9 answers)
Closed 8 years ago.
Trying to see what video categories "me_id" and "you_id" have both watched with:
SELECT c.title, COUNT(*) AS popularity
FROM video v
JOIN user u ON v.user_id = u.id
JOIN v_cat vc ON c.id = vc.vid_id
JOIN cat c ON c.id = vc.cat_id
JOIN u_cat uc ON uc.cat_id = c.id
WHERE uc.user_id = '$me_id'
INTSERSECT
SELECT c.title, COUNT(*) AS popularity
FROM video v
JOIN user u ON v.user_id = u.id
JOIN v_cat vc ON c.id = vc.vid_id
JOIN cat c ON c.id = vc.cat_id
JOIN u_cat uc ON uc.cat_id = c.id
WHERE uc.user_id = '$you_id'
GROUP BY c.title
ORDER BY uc.id DESC LIMIT 0, 10
I am working with PHP/MYSQL any thoughts?
MySQL doesn't have INTERSECT.
JOIN JOIN , Is that valid syntax?
FROM video v JOIN JOIN v_cat vc ON c.id = vc.vid_id
in the above line u have to use join one time..
I see two consecutive JOIN keywords in your first select but without any error message this is going to be difficult to debug.
Instead of INTERSECT, you can use the key word UNION or UNION ALL, this basically will do the intersection select. See http://dev.mysql.com/doc/refman/5.0/en/union.html