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 9118633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:12:02+00:00 2026-06-17T05:12:02+00:00

I am having a terrible time understanding the MySQL documentation on using the IF

  • 0

I am having a terrible time understanding the MySQL documentation on using the IF statements I am hoping someone can simplify it for me. I don’t even know if what I want to accomplish is best done using the MySQL IF statements or if there is a better way to do it using PHP. I am attempting to create an online time card system just for learning/experimenting for now. I have three buttons “Clock in” “Update” and “Clock Out”. “Clock in” is pretty straight forward all I do is add “Employee ID” and “Time in” along with “Date” to the table. The “Update” function is where I am at now. So what I am looking to do with it is:

  1. Add several PHP variables to specified columns in table.
  2. Add the current time to the “time out” column.
  3. Add the current time to the “time in” column in a new row with same “employee ID”.

So the statement I want to make is going to be something like:

IF "timeOut" is NULL
WHERE "employeeID" AND "currentDate"
THEN 
UPDATE "timeRecords" SET "jobDescription", "timeOut"
WHERE "employeeID" AND "currentDate"
THEN
INSERT "timeIn", "employeeID", "currentDate"

Is there even a way to write this in MySQL? If so could someone give me an example of a working MySQL statement the documentation does not provide enough for me to understand it.
Maybe there is a better way to accomplish this I am missing?

  • 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-17T05:12:04+00:00Added an answer on June 17, 2026 at 5:12 am

    You really shouldn’t be using if/then statements in your SQL at all. “control structurs” are for languages like C, PHP or Java -SQL is about “sets”.

    In this particular case, look at the mysql “Replace” statement. It’s probably ideal for your scenario (“if new, then insert; else update”):

    • http://dev.mysql.com/doc/refman/5.0/en/replace.html

    • http://www.mysqltutorial.org/mysql-replace.aspx

      REPLACE INTO table_name(column_name1,column_name2,…) VALUES(value1,value2,…)

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

Sidebar

Related Questions

I am having a terrible time understanding how to get the wrapper to work
I'm having a terrible time with a MySQL query. I've spent most of my
I am having a terrible time understanding the assignment function that is needed, as
Having a terrible time finding RSpec-2 (and rspec-rails ) documentation. Specifically I want to
I am having a terrible time figuring this one out. I have a form.
I am having a terrible time trying to get an input box like the
I'm having a difficult time understanding how to get Rails to show an explicit
I have been having a terrible time trying to compile a python extension -
I'm having a terrible time trying to pull out some values out of an
My title is terrible but I'm having a hard time wrapping my head around

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.