1

I have a customer table

customers
+---------+
|   id    |
+---------+
|    1    |

And a varchar table

customers_varchar
+-------+-----------+
|  id   |   value   |
+-------+-----------+
|  1    | firstname |
+-------+-----------+
|  1    +  lastname |

Here's my select statement

SELECT c.id, cv.value FROM customers AS c
LEFT JOIN customer_varchar AS cv 
ON c.id = cv.id;

What I get is

ROW 1
1 | firstname

ROW 2
1 | lastname

What I would like is

ROW 1
1 | firstname | lastname
DOfficial
  • 485
  • 6
  • 20
  • You will need to provide 1 more piece of information: The column name on how you identify first and last name, then you just join that together. – Norbert Jun 03 '16 at 20:15
  • the column name in this example is value. My situation is a bit more complex but basically I need all the values from the varchar table to join to the user in the users table and output each user with their varchar values as single result – DOfficial Jun 03 '16 at 20:17
  • How do you identify a value as firstname or as lastname? You must have some meta info there... – Norbert Jun 03 '16 at 20:18
  • I have an attribute_type table as well that can be joined to the varchar by attribute_id that identifies the type. Im not so concerned with this at this point as I just want all the values that match the users ID. Currently I can get all the values but they are returned as seperate rows for each value. – DOfficial Jun 03 '16 at 20:23
  • Does the order of the values matter? And do they need to be separate fields in the results? – Uueerdo Jun 03 '16 at 20:24

0 Answers0