0

I have a database related question for WordPress.

My table is represented as follows:

ID | customID | column1 | column2

1      8      _item    item number

2      8      _price    item price

3      9      _item    item number

4      9      _price    item price

I want to retrieve the following rows using a MySQL SELECT statement:

CustomID | _price | _item |

8       item price(from col2)    item number(from col2)
9       item price(from col2)    item number(from col2)

Is this possible? The value _price and _item should be shown as columns with values from column2. How to solve this?

2
  • 1
    How do you know when its an item number or an item price? Does the data literally say item number/item price? Or is the data like Item Number: Z123 and Item Price: $3.35? Commented May 12, 2017 at 17:33
  • ye item number and item price are values for each product. _price and _item are literally _price and _item. I'll try @LSA solution as soon as possible Commented May 13, 2017 at 20:14

1 Answer 1

1

Your tables are designed quite badly. You should build an extra table which maps product and price. However this is what you can do with your solution:

Select t1.customID, t1.column2, t2.column2 from <tablename> t1,
 <tablename> t2 
 where t1.customID = t2.customId 
 and t1.column1 like '_item' 
 and t2.column1 like '_price';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.