Get Post ID With POST METAs In Single MySQL Query
From POSTS->ID, I want the first 12 IDs with post_type = 'product' And with that ID association, I want to fetch all POST META.
I am using this MySQL query, but it is not working:
SELECT posts.ID, postmeta.meta_key, postmeta.meta_value FROM `wp_u8gwgg_posts` as posts INNER JOIN wp_u8gwgg_postmeta as postmeta on posts.ID = postmeta.post_id WHERE posts.`post_type` = 'product' AND posts.post_status = 'publish' ORDER BY posts.ID
It is giving me redundant post_id in data.:
Post ID | Meta Key | Meta Value ++++++++++++++++++++++++++++++++++++++ 12 | _sku | 18945236 12 | _price | 1569.36 12 | _regular_price | 1496.20
I want result as:
Post ID | Meta Key | Meta Value +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 12 | _sku, _price, _regular_price | 18945236, 1569.36, 1496.20
If it is possible, do let me the solution.
IF any better approach to this is also welcome.
SELECT posts.ID, GROUP_CONCAT(postmeta.meta_key ORDER BY posts.ID) meta_keys, GROUP_CONCAT(postmeta.meta_value ORDER BY posts.ID) meta_values FROM wp_u8gwgg_posts as posts INNER JOIN wp_u8gwgg_postmeta as postmeta on posts.ID = postmeta.post_id WHERE posts.post_type = 'product' AND posts.post_status = 'publish' GROUP BY posts.ID ORDER BY posts.ID
- → I can't do a foreign key, constraint error
- → How to implement DbDongle::convertTimestamps as workaround of invalid timestamps with MySql strict
- → MySQL error "Foreign key constraint is incorrectly formed"
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Laravel 5.1 QueryException when trying to delete a project
- → Using Array in '->where()' for Laravel Query Building
- → Chaining "Count of Columns" of a Method to Single Query Builder
- → Laravel Eloquent Joining Strange query
- → convert time using mysql laravel 5
- → How to update a column after an expiration date in MySQL?
- → Foreign key constraint fails on existing key