This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-16. For the latest, interactive version please visit https://mariadb.com/kb/.

Help with syntax error

I am trying to run a sql script in a mariadb version 10.3.38-MariaDB-cll-lve:

SET
@s := '2021-07-12 12:00:00';

SET
@e := '2021-07-12 12:30:00';

INSERT
	INTO
	appointments
        (client_id,
	service_id,
	starts_at,
	ends_at) 
    SELECT
	(
	SELECT
		id
	FROM
		clients c
	WHERE
		c.email = 'some@email.com'),
	(
	SELECT
		id
	FROM
		services s
	WHERE
		s.name = 'ANY'),
	@s,
	@e
WHERE
	NOT EXISTS 
        (
	SELECT
		id
	FROM
		appointments
	WHERE
		(starts_at <= @s
			AND @s < ends_at)
		OR (starts_at < @e
			AND @e <= ends_at)
		OR (@s <= starts_at
			AND starts_at < @e)
            )
  
;

getting this error:

SQL Error [1064] [42000]: (conn=5686202) 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 'WHERE
	NOT EXISTS 
        (
	SELECT
		id
	FROM
		appointments
	WHERE
...' at line 26
  (conn=5686202) 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 'WHERE
	NOT EXISTS 
        (
	SELECT
		id
	FROM
		appointments
	WHERE
...' at line 26
  (conn=5686202) 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 'WHERE
	NOT EXISTS 
        (
	SELECT
		id
	FROM
		appointments
	WHERE
...' at line 26

Could you give me a hint or any solution?

Answer Answered by Daniel Black in this comment.

The "WHERE NOT EXISTS" corresponds to the first SELECT statement. However there is no FROM clause for that SELECT in your syntax.

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.