Link to home
Start Free TrialLog in
Avatar of Nathan Riley
Nathan RileyFlag for United States of America

asked on

MySQL Query Syntax

I have a query that pulls meta data currently like:

SELECT order_id, meta_key, meta_value
FROM wp_woocommerce_order_items i
INNER JOIN wp_woocommerce_order_itemmeta im ON i.order_item_id = im.order_item_id
where meta_key like '%Name - %'
or meta_key like '%Job Title - %'
or meta_key like '%Company - %'
or meta_key like '%Email - %'

Open in new window


The output is:
2668 Name - 1 Nathan Riley
2668 Email - 1 nathan@domain.com
2800 Name - 1 John Smith
2800 Email - 1 john@domain2.com
2800 Name - 2 Jane Doe
2800 Email - 2 jane@domain2.com

How can I modify so the output would be:
2668 Nathan Riley nathan@domain.com
2800 John Smith john@domain2.com
2800 Jane Doe jane@domain2.com

Thanks!
Avatar of David Favor
David Favor
Flag of United States of America image

Use the SUBSTR() function, which can easily trim off some fixed number of leading characters.

https://www.w3resource.com/mysql/string-functions/mysql-substr-function.php provides a good + simple example.
Avatar of Nathan Riley

ASKER

I need them in the same line though, right now they are each their own line, not sure how to do that with substr().
ASKER CERTIFIED SOLUTION
Avatar of hemant saini
hemant saini

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial