I have 3 tables[table_a, table_b, dataz] in a my database, when I create a TRIGGER as follow,
CREATE TRIGGER trigz AFTER INSERT ON table_a
FOR EACH ROW
IF EXISTS (SELECT * FROM table_b WHERE table_b.uid = '123') THEN
INSERT INTO dataz
VALUES('123');
Getting ERROR as,
#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 '' at line 5
I don't understand what I am missing here...
I am using WAMP Server 2.4, anybody have solution ?
EDIT 1(for Nigel Ren)::
SQL :
CREATE TRIGGER trigz AFTER INSERT ON table_a FOR EACH ROW
IF EXISTS (SELECT * FROM table_b WHERE table_b.uid = 1) THEN
BEGIN
INSERT INTO dataz(userid) VALUES('123');
END;
END IF;
ERROR :
#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 '' at line 4
Related
SQL Noob here.
Im using PHP PDO with named placeholders to insert data to my DB but I want to check if the data exists before I insert it.
Here is my statement:
IF NOT EXISTS (SELECT * FROM dc_line_items_transactions WHERE order_id = '3784732' AND product_id = '435062') INSERT INTO dc_line_items_transactions (order_id,refund_id,user_id,transaction_date,product_id,line_item_id,line_subtotal,line_vat,line_total,dc_timestamp) VALUES (:order_id,:refund_id,:user_id,:transaction_date,:product_id,:line_item_id,:line_subtotal,:line_vat,:line_total,:dc_timestamp)
My PDO code works fine as Its being used by other classes to insert varying different types of data.
My error message is as follows:
SQLSTATE[42000]: Syntax error or access violation: 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 'IF NOT EXISTS (SELECT * FROM dc_line_items_transactions WHERE order_id= '3784732' at line 1
i got an error while im trying to execute query views in mysql version 5.7.19
Here is my query :
CREATE ALGORITHM=UNDEFINED DEFINER=`acc_webdev`#`%` SQL SECURITY DEFINER VIEW `view_dash_total` AS
SELECT
COUNT(0) AS `jumlah`,
SYSDATE() AS `tanggal`
FROM `table_laporan`
WHERE (STR_TO_DATE(`table_laporan`.`dt_added`,'%d-%m-%Y') < (SYSDATE() + INTERVAL - (1)DAY))$$
and got this error:
ERROR 1064 (42000): 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 6
but in mysql 5.1.25, there's no error when i execute the query above
please help me out
Either prepend your DDL with DELIMITER $$ or just change your delimiter to ;.
Read more about delimiters here
Try This:
CREATE VIEW `view_dash_total` AS
SELECT
COUNT(0) AS `jumlah`,
SYSDATE() AS `tanggal`
FROM `table_laporan`
WHERE (STR_TO_DATE(`table_laporan`.`dt_added`,'%d-%m-%Y') < (SYSDATE() + INTERVAL - (1)DAY));
How to Update table1 if the table1 primary key existing in table2. I am using following code but it gives mysql syntax error.
CREATE TRIGGER upd_selectoin
BEFORE UPDATE ON customer
FOR EACH ROW
BEGIN
IF NEW.customer_sk IN(SELECT quotation_cname FROM quotation) THEN
UPDATE customer s JOIN quotation m
ON m.quotation_cname = s.customer_sk
SET s.grade = 2
WHERE s.customer_sk = NEW.customer_sk;
END IF;
I got the following Error
#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 '' at line 9
I want to update the customer table grade column if the customer_sk existing in quotation table.Please help me
I'm creating a stored procedure using phpmyadmin for mysql 5.5.55 .
INSERT INTO drama_ (value1,value2,value3,value4,value5,value6)
VALUES (val1,val2,0,0,0,0);
SELECT LAST_INSERT_ID();
but i'm getting a syntax error in SELECT LAST_INSERT_ID();
EDIT :
You have an error your SQL syntax: check the manual that corresponds to your MYSQL server version for the right syntax to use near 'SELECT LAST_INSERT_ID()' at line 4
I'm trying to track the page views by inserting only unique values every 24h.But when I run this query I get a syntax error.
insert ignore into profilepageviews values( '77.777.777.777' , CURRENT_TIMESTAMP, '5') where hitdate NOT LIKE '%2012-06-26%'
Error:
#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 'where hitdate NOT LIKE '%2012-06-26%'' at line 1
You can not use WHERE clause with INSERT, You might want UPDATE