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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:21:10+00:00 2026-05-12T18:21:10+00:00

I’m getting the following data from a MySQL database +—————-+————+———————+———-+ | account_number | total_paid

  • 0

I’m getting the following data from a MySQL database

    +----------------+------------+---------------------+----------+
    | account_number | total_paid | doc_date            | doc_type |
    +----------------+------------+---------------------+----------+
    |             18 |    54.0700 | 2009-10-22 02:37:09 | IN       |
    |            425 |    49.9500 | 2009-10-22 02:31:47 | PO       |
    +----------------+------------+---------------------+----------+

The query is fine and I’m getting the data I need except that the doc_type isn’t very human readable. To fix this, I’ve done the following

CREATE TEMPORARY TABLE doc_type (id char(2), string varchar(60));
INSERT INTO doc_type VALUES 
 ('IN', 'Invoice'),
 ('PO', 'Online payment'),
 ('PF', 'Offline payment'),
 ('CA', 'Credit adjustment'),
 ('DA', 'Debit adjustment'),
 ('OR', 'Order'); 

I then add a join against this temporary table so my doc_type column is easier to read which looks like this

+----------------+------------+---------------------+----------------+
| account_number | total_paid | doc_date            | document_type  |
+----------------+------------+---------------------+----------------+
|             18 |    54.0700 | 2009-10-22 02:37:09 | Invoice        |
|            425 |    49.9500 | 2009-10-22 02:31:47 | Online payment |
+----------------+------------+---------------------+----------------+

Is this the best way to do this? Is it possible to replace the text in one query? I started looking at if statements but it doesn’t seem to be what I’m after or maybe I just read it incorrectly.

// EDIT //

Thanks everyone. I suppose I’ll keep doing it this way.

Unfortunately, it’s not possible to change doc_type to integer as this is an existing database for a billing application I didn’t write. I’d end up breaking functionality if I made any changes other than adding a table here and there.

Also appreciate the easy to understand case statement from Rahul. May come in handy later.

  • 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-05-12T18:21:11+00:00Added an answer on May 12, 2026 at 6:21 pm

    Your current way is the best. Arguably, document_type can be changed to an int, to save space and whatnot, but that’s irrelevant.

    Doing the join will be much faster and readable than any chained ifs.

    Not to mention, extensible. Should you need to add a new doc_type, it’s just an insert vs. potentially several queries.

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

Sidebar

Related Questions

I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

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.