Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Learning Aids/Tools 2 years ago
Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I simplified a many-to-many relationship case with these mockup tables.
Posts: ------------------------------ | id | title | body | ------------------------------ | 1 | One | text1 | | 2 | Two | text2 | | 3 | Three | text3 | ------------------------------ Tags: ------------------- | id | name | ------------------- | 1 | SQL | | 2 | GLSL | | 3 | PHP | ------------------- Post_tags: ------------------------------ | id | p_id | t_id | ------------------------------ | 1 | 1 | 1 | | 2 | 1 | 3 | | 3 | 2 | 1 | | 3 | 3 | 2 | ------------------------------
My goal is to query POSTS with specific TAGS, which I have no problem with, but I also want to display all related tags to the post not just the one I queried for. My query looks like this:
SELECT p.Title, p.Body, t.name FROM Posts p LEFT JOIN Post_tags pt ON p.id = pt.p_id LEFT JOIN Tags t ON t.id = pt.t_id WHERE t.name LIKE '%SQL%'
This gets the posts with the "SQL" tag, but it only joins the posts table with tags where it found the "SQL" string, so the other tag "PHP" associated with the post doesn't get joined.
Obviously the problem is I'm joining the table on the WHERE clause, but how would one solve this in one query or (preferably with subqueries)?
Currently I'm doing this in two separate queries in my application, one for selecting matching posts and another one that is retreiving full post data. This isn't so efficient and also seems like a lame solution, and I haven't found a better yet, so I decided to ask the StackOverflow community.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.