I am trying to create a trigger using PHPMyadmin GUI, but encountered an error MySQL # 1415. Here is my query for the trigger.
SELECT *
FROM `manage_order` O
INNER JOIN `manage_transaction` T ON T.txn_id = O.trans_id
WHERE O.`trans_status` = 'Completed' && O.`order_via` = 'Bid' && O.`release_flag` = 'Y'
ORDER BY O.`added_date` DESC;
INSERT INTO `manage_site_income_details`
VALUES (NULL, T.t_id, T.about, O.order_id, O.order_amt * 0.035, NOW());
Related
I have the below query which works in Mysql Workbench but get an error in hibernate
insert into namingsequences(currentseq, namingtype, scope, sequencekey, startrange, endrange, steprange, rangeactive)
select (a.currentseq + 5) as currentseq, namingtype, scope, sequencekey, startrange, endrange, steprange, rangeactive from namingsequences a
where a.sequencekey = 'test1123' and a.namingtype = 'test' and a.scope = 'test'
and a.currentseq >= a.startrange and a.currentseq <= a.endrange and not exists
(select 1 from namingsequences b where b.sequencekey = 'test1123' and b.namingtype = 'test'
and b.currentseq >= b.startrange and b.currentseq <= b.endrange
and b.scope = 'test' and b.currentseq = (a.currentseq+5) )
order by currentseq ;
insert into NamingSequences ( namingtype, scope, sequencekey,startrange,
endrange, steprange, currentseq, rangeactive )
select namingsequ0_.namingtype as col_0_0_, namingsequ0_.scope as col_1_0_,
namingsequ0_.sequencekey as col_2_0_, namingsequ0_.startrange as col_3_0_,
namingsequ0_.endrange as col_4_0_, namingsequ0_.steprange as col_5_0_,
namingsequ0_.currentseq+? as col_6_0_, namingsequ0_.rangeactive as col_7_0_ from NamingSequences namingsequ0_
where namingsequ0_.sequencekey=? and namingsequ0_.namingtype=? and namingsequ0_.scope=?
and namingsequ0_.currentseq>=namingsequ0_.startrange and namingsequ0_.currentseq<=namingsequ0_.endrange
and not (exists (select 1 from NamingSequences namingsequ1_ where
namingsequ1_.sequencekey=? and namingsequ1_.namingtype=?
and namingsequ1_.currentseq>=namingsequ1_.startrange
and namingsequ1_.currentseq<=namingsequ1_.endrange
and namingsequ1_.scope=? and
namingsequ1_.currentseq=NamingSequences.currentseq+?))
order by namingsequ0_.currentseq
[DEV: 2018-Feb-28 16:32:47,884][WARN ][http-nio-8082-exec-35]SQL Error: 1054, SQLState: 42S22
[DEV: 2018-Feb-28 16:32:47,884][ERROR]http-nio-8082-exec-35 Unknown column 'NamingSequences.currentseq' in 'where clause'
It seems that it cannot access the outer query field from the subquery. The error seems to be from the hibernate query penultimate line.
Also, can i restrict that only one row will be returned by select and inserted?
Query hbquery = session.createQuery(queryString);
hbquery.setMaxResults(1);
hbquery.setParameter("scope", scope);
hbquery.setLong("increment", step);
hbquery.setParameter("nameType", namingType);
hbquery.setParameter("seqKey", seqKey);
int ret = hbquery.executeUpdate();
Not done any programming for a few years so am somewhat rusty again.
I have two tables users table and users_profiles table. I want to update users_profiles table on the condition that user_uid matches on both tables (users.user_uid and users_profiles.user_uid) and where users.user_login = 'johndoe' and users.user_uid = '11'.
It will be executed in a php script, so johndoe would actually be users username (whatever is stored in session and same for users_uid. For simplicitity i added dummy data.
I run the query in phpmyadmin and get syntax error near INNER JOIN. I just cannot figure out what i'm doing wrong (probably wrote it entirely wrong) and have spent few hours trying to work it out without success.
Heres my sql query.
UPDATE
users_profiles
SET
users_profiles.user_fname = 'John',
users_profiles.user_lname = 'Doe',
users_profiles.user_gender = 'male'
INNER JOIN
users
ON
users.user_uid = users_profiles.user_uid
WHERE
users.user_login = 'johndoe'
AND
users.user_uid = '11'
error i get when running sql query via phpmyadmin.
#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 'ON users.user_uid, .user_uid FROM users_profiles WHERE
users.user_login ' at line 7
Thanks.
Try this:
UPDATE
users_profiles
INNER JOIN
users
ON
users.user_uid = users_profiles.user_uid
SET
users_profiles.user_fname = 'John',
users_profiles.user_lname = 'Doe',
users_profiles.user_gender = 'male'
WHERE
users.user_login = 'johndoe'
AND
users.user_uid = '11'
Try to exchange SET and INNER JOIN as shown, for example, in this SO answer:
UPDATE
users_profiles p
INNER JOIN
users u
ON
u.user_uid = p.user_uid
SET
p.user_fname = 'John',
p.user_lname = 'Doe',
p.user_gender = 'male'
WHERE
u.user_login = 'johndoe'
AND
u.user_uid = 11
Hi I'm trying to write a cursor in powerbuilder 12 to fetch some records . Here this is my query.
I'm trying to fetch some records from the trninvhdr table which are not in the second table.
SELECT
INV_DATE,
INV_NO,
INV_TYPE,
CUR_CODE,
EXCH_RATE,
usd_rate,
CR_TERM,
DUE_DATE,
bl_date,
TOT_AMT
FROM trninvhdr
WHERE
COMP_CODE ='NFL1' AND
CUST_CODE = 'NLML' AND
INV_TYPE ='F' AND
INV_DATE <= '2016-03-25' AND
NOT EXISTS
(SELECT * FROM trninvoiceavailability WHERE trninvoiceavailability.COMP_CODE = trninvhdr.COMP_CODE
AND trninvoiceavailability.INV_TYPE = trninvhdr.INV_TYPE AND trninvoiceavailability.INV_NO = trninvhdr.INV_NO);
Here how I use it in the program.
DECLARE lc_retrieve CURSOR FOR
SELECT
trninvhdr.INV_DATE,
trninvhdr.INV_NO,
trninvhdr.INV_TYPE,
trninvhdr.CUR_CODE,
trninvhdr.EXCH_RATE,
trninvhdr.usd_rate,
trninvhdr.CR_TERM,
trninvhdr.DUE_DATE,
trninvhdr.bl_date,
trninvhdr.TOT_AMT
FROM trninvhdr
WHERE
COMP_CODE = :as_comp_code AND
CUST_CODE = :as_cust_code AND
INV_TYPE ='F' AND
INV_DATE <= :as_inv_date )AND
NOT EXISTS (SELECT * FROM trninvoiceavailability
WHERE trninvoiceavailability.COMP_CODE = trninvhdr.COMP_CODE
AND trninvoiceavailability.INV_TYPE = trninvhdr.INV_TYPE AND
trninvoiceavailability.INV_NO = trninvhdr.INV_NO);
open lc_retrieve ;
The query works fine in the mysql server but in the progra it gives me the following error .
Database c0038 SQLSTATE = 3700 MySQL ODBC 5.2 a Driver mysql id 5.5.25 You have an error in your syntax. check the manual that corresponds to your mysql version for the right syntax to use near NOT EXISTS (SELECT * FROM trninvoiceavailability.... at line 1.
What is the correct Syntax that I should use to work this query.
I can see a bracket in this code... where did it come from and where is it's friend?
INV_DATE <= :as_inv_date )AND
You need to remove ) from your query as per below-
INV_DATE <= :as_inv_date )AND
sholuld be INV_DATE <= :as_inv_date AND
so I am trying to run this sql:
UPDATE creature_template
SET
subname = "Utgarde Keep Heroics",
Health_mod = Health_mod * 45,
mindmg = mindmg * 100,
maxdmg = maxdmg * 100,
Armor_mod = armor_mod * 4
WHERE entry IN (
SELECT difficulty_entry_1
FROM creature_template
WHERE entry IN (
SELECT id FROM creature WHERE map = 574
)
);
But I am getting this error:
[Err] 1093 - You can't specify target table 'creature_template' for update in FROM clause
How am I supposed to run it?
You cannot update the same table that you use in the SELECT part in MySQL. You'll need to use a sub-query like below to create a temporary table in the nested sub-query and it will not count as the same table you are updating:
UPDATE creature_template
SET
subname = "Utgarde Keep Heroics",
Health_mod = Health_mod * 45,
mindmg = mindmg * 100,
maxdmg = maxdmg * 100,
Armor_mod = armor_mod * 4
WHERE entry IN (
SELECT difficulty_entry_1
FROM (creature_template
WHERE entry IN (
SELECT id
FROM creature ) as temp
WHERE map = 574
)
);
See also MySQL documentation on the UPDATE syntax
Hope this helps
Query syntax is wrong.
You can update the same table that is referenced in selcting the entry.
Check this link:
MySQL DOCUMENT FOR THIS:
I am working from 2 databases and I need to find records which matches the closest times. Both fields are datetime().
So in essence:
table1.time = 2012-06-07 15:30:00
table2.time = 2012-06-07 15:30:01
table2.time = 2012-06-07 15:30:02
table2.time = 2012-06-07 15:30:03
NOTE: The table I am querying (table2) is a mssql table, and table1.time is a datetime() time. I need to find in table2 the row which closest matches table1.time, but I have no guarnatee that it would be an exact match, so I need the closest. I only need to return 1 result.
I tried the SQL below based on an example from a previous stackoverflow query but it failed to work.
Table1 is a mysql database where table2 is mssql and the query happens on table2 (mssql)
try {
$sql = "
SELECT
PCO_AGENT.NAME,
PCO_INBOUNDLOG.LOGIN AS LOGINID,
PCO_INBOUNDLOG.PHONE AS CALLERID,
PCO_INBOUNDLOG.STATION AS EXTEN,
PCO_INBOUNDLOG.TALKTIME AS CALLLENGTH,
PCO_INBOUNDLOG.CHANNELRECORDID AS RECORDINGID,
PCO_SOFTPHONECALLLOG.RDATE,
PCO_INBOUNDLOG.RDATE AS INBOUNDDATE
FROM
PCO_INBOUNDLOG
INNER JOIN
PCO_LOGINAGENT ON PCO_INBOUNDLOG.LOGIN = PCO_LOGINAGENT.LOGIN
INNER JOIN
PCO_SOFTPHONECALLLOG ON PCO_INBOUNDLOG.ID = PCO_SOFTPHONECALLLOG.CONTACTID
INNER JOIN
PCO_AGENT ON PCO_LOGINAGENT.AGENTID = PCO_AGENT.ID
WHERE
PCO_INBOUNDLOG.STATION = :extension
AND ABS(DATEDIFF(:start,PCO_SOFTPHONECALLLOG.RDATE))
";
$arr = array(":extension" => $array['extension'], ":start" => $array['start']);
$query = $this->mssql->prepare($sql);
$query->execute($arr);
$row = $query->fetchAll(PDO::FETCH_ASSOC);
$this->pre($row);
}
I am getting the following error at the moment:
SQLSTATE[HY000]: General error: 174 General SQL Server error: Check messages from the SQL Server [174] (severity 15) [(null)]SQLSTATE[HY000]: General error: 174 General SQL Server error: Check messages from the SQL Server [174] (severity 15) [(null)]
Found a shorter version:
SELECT * FROM `table` WHERE `date` < '$var' ORDER BY date LIMIT 1;