Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:47:36+00:00 2026-06-10T07:47:36+00:00

Do you see any issues with this MySQL query? It does not execute. Any

  • 0

Do you see any issues with this MySQL query? It does not execute.
Any other better ideas?

INSERT INTO registration 
   ( m_ID,  e_ID,   STATUS) 
SELECT 
   :m_ID, :e_ID, 1
WHERE 
    EXISTS ( SELECT 1 FROM tableb WHERE ID = :e_ID)
AND EXISTS ( SELECT 1 FROM tablec WHERE m_ID = :m_ID)

Passing array with values for e_id and m_ID (PDO)

Basically the goal is to check if both IDs exists in different tables before inserting onto another table.

ERROR:

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 'WHERE EXISTS ( SELECT 1 FROM tableb WHERE ID = '276') AND EX' at 
line 4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:47:38+00:00Added an answer on June 10, 2026 at 7:47 am

    if both IDs exists in different tables

    Yet your query searches tableb twice. Unless you really meant “in a single different table” (and I don’t think so, you’d have used a single EXISTS), then this might be the error you wanted.

    Also, PDO should have some sort of error logging. The query might not execute, but the reason should appear – or it should be possible to make it appear – somewhere.

    UPDATE

    I’m afraid I was wrong, the syntax is not correct. MySQL doesn’t allow SELECT ... WHERE unless a table is specified.

    Try changing

    SELECT 
       :m_ID, :e_ID, 1
    WHERE EXISTS
    

    in

    SELECT * FROM
       ( SELECT :m_ID, :e_ID, 1 ) AS dummy
    WHERE EXISTS
    

    TEST:

    mysql> SELECT 42;
    +----+
    | 42 |
    +----+
    | 42 |
    +----+
    1 row in set (0.00 sec)
    
    mysql> SELECT 42 WHERE true;
    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 'WHERE true' at line 1
    
    
    mysql> SELECT * FROM ( SELECT 42 ) AS answer WHERE true;
    +----+
    | 42 |
    +----+
    | 42 |
    +----+
    1 row in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql statement like this: mysql_query(INSERT INTO movies (comments, description, synopsis) VALUES
I hardly see any pointer on the following problem related to Hibernate. This pertains
I don't see any documentation or core code to specifically address Insert ... On
The problem is that the Eclipse compiler do not see any layout or ids,
Solution found, see my comment below D5, odbc to mysql database This code: with
The code below is meant to insert values into a MySQL Database if the
I am curious to see any alternative(s) to the regular if statements such as
I can't see any info about that. Where can I find the oldest date
I didn't see any output in the console or Visual Studio's output panel from:
I dont see any direct mention on using multiple slugs (or any behavior for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.