SELECT er.pNumber, er.name, ep.fPosition, eo.res
FROM events_shot er, events_shot_final ep, events_shot_final_res eo, events_gear era
WHERE era.idShot=er.idShot AND ep.idPhoto=era.idPhoto AND eo.idShot=era.idShot
AND era.idShot=42 AND eo.shotType='PRT'
AND er.pNumber IN (
SELECT *
FROM STRING_SPLIT(eo.photosId,'-')
)
shotsId is a String like 12-1-8-7... with n pNumber id separated by '-'
Unfortunately the query return this error:
Error Code: 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 '(eo.photosId,'-') )' at line 7
I can't change the database, how can I change my query?
Any help you can provide would be appreciated.
Fix your data model! Don't store multiple values in a single column.
Learn proper SQL syntax! Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax.
With that said, you don't need to split the string. You can use string operations:
AND CONCAT('-', eo.photosId, '-') LIKE CONCAT('%-', er.pNumber, '-%')
But you should really start work on fixing the data model as soon as you get this query to work.
Related
The goal is to query multiple IP addresses. I am using HeidiSQL to run this query.
Error:
SQL 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 "10.3.22.14" at line 1.
SQL query:
set #trunk='10.3.22.5','10.3.22.14';
set #sdate='2021-06-29 00:00:00', #edate='2021-06-29 23:59:00';
SELECT acctstarttime, acctstoptime, acctsessiontime, calledstationid, callingstationid, username, acctterminatecause, h323disconnectcause, h323calltype, acctstatustype, nasipaddress, nasportid, h323remoteaddress, acctinputoctets, servicetype, acctoutputoctets
FROM radius.radacct
where (acctstarttime between #sdate and #edate )
and nasipaddress in (#trunk);
How can I fix this syntax error?
You can not define a list as variable.
set #trunk='10.3.22.5','10.3.22.14';
Define a comma-separated list, and use FIND_IN_SET.
set #trunk='10.3.22.5,10.3.22.14';
select FIND_IN_SET('10.3.22.5', #trunk);
refer
First, I don't really recommend what you are doing. But to get the correct syntax, you need to realize that ' is a special character in SQL. It is a string delimiter. So:
set #trunk='10.3.22.5','10.3.22.14';
is just two strings next to each other. And MariaDB does not recognize that syntax. What you are trying to do is:
set #trunc = '10.3.22.5,10.3.22.14'
Then, you can use this in the query not with in, but using find_in_set():
where find_in_set(nasipaddress, #trunc) > 0
Note that using the function find_in_set() prevents the use of indexes. So, if your table is large, then another solution is preferable, perhaps by storing the values in a table and using join.
Cannot define list as a variable.
set #trunk="10.3.22.5,10.3.22.14";
select FIND_IN_SET("10.3.22.5", #trunk);
I have been trying to run this mysql query through rstudio, but I keep getting an error. Any idea why?
Here is my query:
SELECT host.key AS 'uid',
daily_summary.date AS 'date'
FROM host INNER JOIN daily_summary
USING(weekly_id);
This is the error I get.
42000 1064 [MySQL][ODBC 5.1 Driver][mysqld-5.5.40-
0ubuntu0.14.04.1]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 'FROM host INNER
JOIN daily_summary USING(weekly_id)' at line 1
This is the query as it would better be written:
SELECT host.key AS uid, daily_summary.date
FROM host INNER JOIN
daily_summary
USING(weekly_id);
In addition to removing the spurious commas, this also removes the unneeded quotes around the column aliases. Only use single quotes for string and date constants. Otherwise, they are likely to cause confusion in queries. If you need to escape aliases in MySQL, then use backticks.
Check version simplified without typos:
SELECT host.key, daily_summary.date
FROM host INNER JOIN daily_summary
USING(weekly_id);
I also prefer to use word ON instead of USING:
SELECT host.key, daily_summary.date
FROM host INNER JOIN daily_summary
ON host.weekly_id = daily_summary.weekly_id
The MySQL syntax error message shows you part of your statement starting with the first character it can't understand. In your case the first characters it can't understand are FROM. It's looking for another column name after the comma.
I am trying to find a weird character thats in front of my £ sign and replace it with nothing.
Coding I tried was
update [orders_total]
set [text]=replace([text],'[Â]','[]');
but mysql returns this
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 '[orders_total] set [text]=replace([text],'[Â]','[]')' at line 1
I know nothing of Mysql but its going to take me ages to manually remove these chars so any help would be much appreciated.
Thanks in advance
Thats not mysql syntax and in mysql it should be as
update orders_total
set text=replace(text,'Â','');
Abhik is absolutely right in his answer. An alternate form of writing MySQL queries is:
update `orders_total` set `text` = replace(`text`, '..', '...');
Backticks are not required. They may be valuable when a table's column is named order, for example. Order is a reserved keyword used in order by ... clause. In order to use a reserved keyword like order, use backticks.
Example:
select `order`, `id`, ... from `tablename` where .... order by `order`;
IF OBJECT_ID(N`db_291702_2`.`aaCoRrankingDateManage`, N'U') IS NOT NULL
BEGIN
PRINT 'Table Exists'
END
What is wrong with this? Why do I get errors?
Neither of the suggested ways in how-to-check-if-a-table-exists-in-sql-server/ works for me.
PS. "does not work" means errors like
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 ''db_291702_2'.'aaCoRrankingDateManage' LIMIT 0, 30' at line 1
Additional info:
I am using phpMyAdmin, my two databases are called db_291702_1 and db_291702_2, the latter has two tables, one of them is called aaCoRrankingDateManage
If you want to escape table or column names then use backticks
select `group` from table1
A static string must be included in quotes
select * from users where name = 'john'
And the syntax of every DB engine is a little bit different. The above works for MySQL, but SQL-Server has a different syntax. There you use brackets [] to escape names.
But you only need to escape names if you use reserved words. You don't have to escape everything.
The given source code is no MySQL Code.
i am trying to get the result from thquery, but i am getting error on the line 2, where i am using the cast function:
SELECT ticketstickets.`ID`, ticketsusers.`fname`, ticketsusers.`lname`, ticketstickets.`subject`,
ticketstickets.`created`, CAST(ticketstickets.modified AS VARCHAR(100)) as modified,
ticketstickets.`priority`, ticketstickets.`status`,
ticketsdepartments.`name` FROM ticketsusers, ticketstickets
LEFT JOIN ticketsdepartments ON ticketstickets.`DEPARTMENT_ID`= ticketsdepartments.`ID`
WHERE ticketstickets.parent = 0
AND ticketstickets.by=ticketsusers.ID
I tried with convert function too, but same error: [Err] 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
'VARCHAR(100)) as modified,
ticketstickets.priority, ticketstickets.`s' at line 2
Please see in the manual that a value cannot be casted to varchar(N). Instead you should cast to char(N) (so without "var").
use that instead
CAST(ticketstickets.modified AS CHAR(100))
Probably the issue is in your CAST statement.
Refer this post to correct your query:
How to use the CAST function correctly in a MySql SELECT statement?