Can anyone help with this? I've just switched web servers and I'm testing everything is working but I'm seeing this error. Any ideas whats wrong with the query? It seemed to be valid on my last host
Critical Error
A database error has occoured.
Error Returned mySQL query error: SELECT f.* AS fixtures,
team1.teamName AS HomeTeam,
team1.tid AS HomeTeamID,
team2.teamName AS AwayTeam,
team2.tid AS AwayTeamID,
GROUP_CONCAT(n.extra separator ',') AS scorers,
GROUP_CONCAT(n.homeEvent separator ',') AS homeEvent,
GROUP_CONCAT(n.eventType separator ',') AS eventType
FROM fixtures f
LEFT JOIN notifications n ON n.fixtureID = f.fid
LEFT JOIN teams team1 ON team1.tid = f.HomeTeam
LEFT JOIN teams team2 ON team2.tid = f.AwayTeam
WHERE f.kickoff > 1403823600 AND f.lid=1
GROUP BY f.fid
ORDER BY n.time ASC, f.kickoff ASC
mySQL error:
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 fixtures,
team1.teamName AS HomeTeam,
team1.tid AS HomeTeamID,
' at line 1
You can't cast a wildcard like that.. Casting is only for single fields
SELECT f.* AS fixtures
Try something like
SELECT f.fixtures AS fixtures, f.field AS field
etc
I don't know what kind of sql engine did you run on your previous webserver, but this is actually not allowed:
SELECT f.* AS fixtures
You need to specify a column, you can't use the wildcard for casting.
Related
I am using PHP-MySQLi-Database-Class to construct the queries, it is working fine on MySQL but after switching to a MariaDB database a single query in specific is throwing this error: (sorry for the long text)
*Uncaught Exception: 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 'JSON) FROM attributes AS _sub_attr WHERE JSON_EXTRACT(sub_prop_attr.attrib_te...' at line 1 query: SELECT ,p.id AS id, DATEDIFF(CURDATE(),DATE(p.created)) AS days, COALESCE(bed_room,bath_room,parking,construction_size,lot_size,floors,building_age) AS chs , (SELECT JSON_OBJECTAGG(attribute_name, (SELECT CAST(CONCAT('[',GROUP_CONCAT(JSON_QUOTE(_sub_attr.attribute_name)),']') AS JSON) FROM attributes AS _sub_attr WHERE JSON_EXTRACT(sub_prop_attr.attrib_terms, JSON_UNQUOTE(JSON_SEARCH(sub_prop_attr.attrib_terms, 'one', _sub_attr.id))) IS NOT NULL)) FROM prop_attributes AS sub_prop_attr LEFT JOIN attributes AS sub_attr ON sub_prop_attr.attribute_id = sub_attr.id WHERE prop_id = p.id) AS JSON_attributes FROM properties p LEFT JOIN (SELECT id, state_name, CONCAT("en ",state_name) AS state_alias FROM states) s on p.state=s.id LEFT JOIN (SELECT id, city_na in C:\wamp64...\classes\MysqliDb.php on line 1819
...And this is the query:
SELECT *,p.id AS id, DATEDIFF(CURDATE(),DATE(p.created)) AS days,
COALESCE(bed_room,bath_room,parking,construction_size,lot_size,floors,building_age) AS chs ,
(SELECT JSON_OBJECTAGG(attribute_name,
(SELECT CAST(CONCAT(\'[\',GROUP_CONCAT(JSON_QUOTE(_sub_attr.attribute_name)),\']\') AS JSON)
FROM attributes AS _sub_attr
WHERE JSON_EXTRACT(sub_prop_attr.attrib_terms, JSON_UNQUOTE(JSON_SEARCH(sub_prop_attr.attrib_terms, \'one\', _sub_attr.id))) IS NOT NULL))
FROM prop_attributes AS sub_prop_attr LEFT JOIN attr';
This is the MySQL query:
$Srelated_attributes = ", (SELECT JSON_OBJECTAGG(attribute_name, (SELECT CAST(CONCAT('[',GROUP_CONCAT(JSON_QUOTE(_sub_attr.attribute_name)),']') AS JSON) FROM attributes AS _sub_attr WHERE JSON_EXTRACT(sub_prop_attr.attrib_terms, JSON_UNQUOTE(JSON_SEARCH(sub_prop_attr.attrib_terms, 'one', _sub_attr.id))) IS NOT NULL)) FROM prop_attributes AS sub_prop_attr LEFT JOIN attributes AS sub_attr ON sub_prop_attr.attribute_id = sub_attr.id WHERE prop_id = p.id) AS JSON_attributes";
The last is part of a long query and if I take out that part it would work... I think it may be related to quotes or maybe JSON functions but I haven't find any nice solution to make that same code work.
Do any of you have had a related experience? Hope I was clear with my problem description.
I expect I can use my query. Also I've tried erasing the part of the query which I quoted in the issue description and the error disappears so I the problem may be arround that part of the query.
Because JSON isn't a type in the SQL standard, MariaDB hasn't implemented the CAST(... AS JSON) as its not a type.
If you remove those words and the CAST operator will behave in the same way.
I have managed to get a result that says full_name and facility_name.
Here the facility names consists of "Tennis Court1","Tennis Court2","Squash Court", "Badminton" and "Table Tennis"
I now want to filter and present by only "Tennis Court"
I have tried adding
WHERE facility_name ILIKE '%Tennis Court%
but get an error that says:
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 'ILIKE '%Tennis%' at line 15
SELECT
DISTINCT(CONCAT(z.firstname,' ', z.surname)) AS full_name,
facilities.name AS facility_name
FROM
(SELECT members.memid,
bookings.facid,
members.firstname,
members.surname
FROM Members AS members
RIGHT JOIN Bookings AS bookings
ON members.memid =bookings.memid) z
RIGHT JOIN Facilities as facilities
ON facilities.facid = z.facid
WHERE facility_name LIKE 'Tennis Court%'
Here are the links to the table.
TABLES used in the SQL query
The error : #1054 - Unknown column 'facility_name' in 'where clause'. Just to inform you. There are 2 facility names 'Tennis Court1' and 'Tennis Court2'
Replace ILIKE TO LIKE in your query and remove brackets after distinct as distinct is not a function
Incidentally, your query appears to be functionally identical to:
SELECT DISTINCT CONCAT_WS(' ',m.firstname,m.surname) full_name
, f.name facility_name
FROM facilities f
JOIN bookings b
ON b.facid = f.facid
LEFT
JOIN members m
ON m.memid = b.memid
WHERE f.name LIKE 'Tennis Court%'
And, if I'm wrong, see Why should I provide an MCRE for what seems to me to be a very simple SQL query
Thank you very much
I used facid instead of facility_name
The code goes as follows:
SELECT
DISTINCT CONCAT(z.firstname,' ', z.surname) AS full_name,
facilities.name as facility_name
FROM
(SELECT members.memid,
bookings.facid,
members.firstname,
members.surname
FROM Members AS members
RIGHT JOIN Bookings AS bookings
ON members.memid =bookings.memid) z
RIGHT JOIN Facilities as facilities
ON facilities.facid = z.facid
WHERE facilities.facid=0 OR facilities.facid=1
This it the code I am trying to execute:
SELECT ID_K
FROM koncert,
programi
WHERE koncert.ID_K = programi.ID_K
GROUP BY koncert.ID_K
HAVING COUNT (DISTINCT programi.Salla) = 2
It returns this 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 'DISTINCT programi.Salla)=2 LIMIT 0, 25' at line 4.
Tried to change different things but it still won't work .
You should use the count(DISTINCT programi.Salla
) and not count (..) ..remove space between COUNT and (...
SELECT koncert.ID_K
FROM koncert
INNER JOIN programi on koncert.ID_K = programi.ID_K
GROUP BY koncert.ID_K
HAVING COUNT(DISTINCT programi.Salla) = 2
but you need also tablename for avoid ambiguity and use explicit join sintax too
First you should use qualified name for your column, when column name is same in both table
SELECT ID_K FROM
should be
SELECT programi.ID_K FROM
else, you will get ambiguous column error. Otherwise, your query looks fine except removing extra space when calling COUNT (#spencer already mentioned in comment)
Also, it is good practice to join your table using JOIN (or INNER JOIN, LEFT JOIN etc) keyword, which makes your query more clear and readable.
The following query gives me an error in phpmyadmin. It looks syntactically correct to me, and the table/column names match up accordingly. I have tried a number of variations (quoting table names, using as, etc) with no luck.
SELECT *
FROM GROUP
INNER JOIN GROUP_MEMBER ON GROUP.group_id = GROUP_MEMBER.group_id
WHERE group_owner='test';
Error I'm getting:
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 'GROUP INNER JOIN GROUP_MEMBER ON GROUP.group_id = GROUP_MEMBER.group_id WHERE ' at line 2
"group" is a sql-keyword, you need to surround it with backticks if you want to use it as tablename.
GROUP is a reserved word in SQL so it's a bad choice for a table name. If you surround it with backticks it might work but I'd really recommend changing that table name.
SELECT *
FROM `GROUP`
INNER JOIN GROUP_MEMBER ON `GROUP`.group_id = GROUP_MEMBER.group_id
WHERE group_owner='test';
This is not PHPMyAdmin-specfiic error. The problem you have is using a table name GROUP that matches a MySQL reserved word. If you insist on using such a problematic table name, you need to enclose it with backticks anywhere you might use it.
SELECT *
FROM `GROUP`
INNER JOIN GROUP_MEMBER ON `GROUP`.group_id = GROUP_MEMBER.group_id
WHERE group_owner='test';
Like this:
SELECT s.*, count( logs.* ) as ssh_count
FROM servers s
LEFT JOIN logs ON s.ip_address = logs.server_ip
But I get an error with that query:
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 ssh_count FROM servers s LEFT JOIN logs ON s.ip_address = logs.server_ip LIMIT' at line 1
I think that's because you can't address a table in the count function.
I can do this using a subquery, but that will likely slowly down the query.
What is a better way of doing this?
You can adress a table column, but you can't address table.*, you can do this for example:
SELECT s.*, count( logs.server_ip ) as ssh_count
FROM servers s
LEFT JOIN logs ON s.ip_address = logs.server_ip