-1

Dear visitors of Stack Overflow,

I am building a research application in PHP where the user can enter it's own variables. These variables are often numerical. A text label can be attached to each numerical value to improve the readability of the data. That is, the records are displayed as:


Record1: Value0, Value1, Value1, Value3, Value2

Record2: ..


instead of:


Record1: 0, 1, 1, 3, 2

Record2: ..


In order to transform the numerical data to their label counterparts I would have to perform a great number of joins to the (same) table holding the textual representation (the label). My question is twofold:

  1. Will performing multiple joins to the same table (aliased) in MySQL impact the performance by much?
  2. What would be the best SQL syntax for such a join?

Of course I welcome any other suggestions!

I look forward to your answers!

Tom

Tom
  • 1
  • 1
  • Deleted my answer but felt this comment from the OP was worth posting here for others: "It is entirely possible that a user will have 100 variables which would require 100 joins to the label table per retrieval of one record. I am wondering how much of a difference in performance there will be achieving this through SQL only (preferred because of flexibility) or performing two separate queries, replacing the data with labels in PHP?" – Fosco Feb 13 '12 at 04:54

1 Answers1

0

Why not have a record structure like this:

table `user_variables`:
    user_id   int
    var_name char,
    var_value char

No self joins required, as each name/value pair has its own record.

Marc B
  • 356,200
  • 43
  • 426
  • 500