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

  • SEARCH
  • Home
  • 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 8959121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:22:32+00:00 2026-06-15T15:22:32+00:00

I’m having a little trouble with my SQL queries and I keep getting a

  • 0

I’m having a little trouble with my SQL queries and I keep getting a syntax error I can’t figure out.

The query in question is:

INSERT INTO $db (uuid, quest, stage, completion, quest_id, dstart) VALUES ('".$avatar_key."','".$quest_name."','".$quest_stage."','".$qc."','".$quest_id."','".$date."') WHERE NOT EXISTS (SELECT *
       FROM $db
       WHERE uuid = '$avatar_key' AND quest_id = '$quest_id'
       )

What I’m trying to do is to check if the table has a row, with both the exact values of $avatar_key and $quest_id, and if such a row does NOT exist, then I want it to INSERT a new one.

I’m getting an error I can’t seem to figure out how to fix though; the query itself looks to me (though I’m a SQL newbie) that is /should/ work. I’m using SQL 5.5, & this is the error message I’m getting:

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 NOT EXISTS (SELECT *
FROM sldb_quest
WHERE uuid = ‘0089dcea-‘ at line 1

I know that having a unique identifier would’ve helped that, but the database is going to store a LOT of rows, many of which will have identical values and the only unique value will be the UUID, which I must then match up with the quest_id in order to find the specific row I want.
The uuids look something like this: “0089dcea-bf39-40f5-859e-d79bdc383f1b” and are uniquely generated for every user.

Any pointers as to what I’m doing wrong would be very appreciated! I’m sure it’s just a small detail I’ve managed to miss somewhere, but I’ve not had any luck finding the cause.

  • 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-15T15:22:33+00:00Added an answer on June 15, 2026 at 3:22 pm

    A WHERE clause is not valid on a INSERT with a VALUES list. You can use INSERT ... ON DUPLICATE UPDATE, but I’m not sure an update is what you want.

    If uuid (with or without quest_id) is set as a unique key, the simplest thing you can try is to use IGNORE.

    INSERT IGNORE INTO $db (uuid, quest, stage, completion, quest_id, dstart) 
    VALUES ('".$avatar_key."','".$quest_name."','".$quest_stage."','".$qc."','".$quest_id."','".$date."')
    

    And if you don’t have a unique key yet, I strongly recommend you make one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.