Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question: Largest Hub for Question Solutions and Expert Answers

Querify Question: Largest Hub for Question Solutions and Expert Answers Logo Querify Question: Largest Hub for Question Solutions and Expert Answers Logo

Querify Question: Largest Hub for Question Solutions and Expert Answers Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 770637

Querify Question: Largest Hub for Question Solutions and Expert Answers Latest Articles

admin
  • 163
adminEnlightened
Asked: July 14, 20242024-07-14T05:08:20+00:00 2024-07-14T05:08:20+00:00

sql subquery select data from three tables

  • 163

I'm using this query to get data from mysql. Can it be improved? It takes around 0.2s for each query…

I found some other way such as left join but I can't get all data with one query.


Or do I need to use two queries?

  1. Select p.id, p.post_date, p.post_content, p.post_title, p.post_name, p.guid

  2. for loop -> likes_count, dislikes_count, post_views_count, rate where post_id = p.id?


SELECT p.id, p.post_date, p.post_content, p.post_title, p.post_name, p.guid,  (SELECT guid FROM wp_posts WHERE id = (SELECT meta_value FROM wp_postmeta WHERE post_id = p.id AND meta_key =  "_thumbnail_id")) AS thumbnail_url,  (SELECT GROUP_CONCAT(DISTINCT term_taxonomy_id) FROM wp_term_relationships WHERE object_id = p.id) AS term_taxonomy_id,  (SELECT meta_value FROM wp_postmeta WHERE post_id = p.id AND meta_key =  "likes_count" LIMIT 1) AS likes_count,  (SELECT meta_value FROM wp_postmeta WHERE post_id = p.id AND meta_key =  "dislikes_count" LIMIT 1) AS dislikes_count,  (SELECT meta_value FROM wp_postmeta WHERE post_id = p.id AND meta_key =  "post_views_count" LIMIT 1) AS post_views_count,  (SELECT meta_value FROM wp_postmeta WHERE post_id = p.id AND meta_key =  "rate" LIMIT 1) AS rate  FROM wp_posts AS p INNER JOIN wp_term_relationships AS t ON p.id = t.object_id   WHERE p.post_status="publish"  AND p.ping_status="open"  AND t.term_taxonomy_id = ? GROUP BY p.id LIMIT ?,? 

[EDIT-1] [Table structure]1


[EDIT-2] The Output

{"id":11111,"post_date":"2016-01-02T05:46:58.000Z","post_content":"contenttttttt","post_title":"titleeeee","post_name":"postname","guid":"1255322","thumbnail_url":"thumb1957.jpg","term_taxonomy_id":"7","likes_count":"1","dislikes_count":"1","post_views_count":"538","rate":"50"} 

Related Posts
  • Related Link: sql query to find the attendance of the group leader should be greater than the avg attendance of all members of his group
mysqlsql
  • 0 0 Answers
  • 1k Views
  • 0 Followers
  • 1k
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 1mil
  • Answer 1
  • Best Answers 0
  • Users 40k
  • Popular
  • Answers
  • admin

    vba code excel range not pasting to outlook properly

    • 1 Answer
  • MilaBrext

    Заказать Хавал - только у нас вы найдете цены ниже ...

    • 0 Answers
  • admin

    Creating a Regex to Match the First N Characters of ...

    • 0 Answers
  • Reda
    Reda added an answer Convert Range to Text February 27, 2025 at 8:30 pm

Top Members

admin

admin

  • 1mil Questions
  • 855 Points
Enlightened
Reda

Reda

  • 0 Questions
  • 22 Points
Begginer
Aria Carter

Aria Carter

  • 0 Questions
  • 21 Points
Begginer

Trending Tags

android azuredevops azurepipelines c database debugging decimal docker html ios java javascript jquery php python reactjs regex rubyonrails sql vlc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question: Largest Hub for Question Solutions and Expert Answers

Querify Question: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.