vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need Help with double LEFT JOIN SQL Query (https://vborg.vbsupport.ru/showthread.php?t=182137)

ZomgStuff 06-11-2008 01:51 AM

Need Help with double LEFT JOIN SQL Query
 
So currently this is my query.

PHP Code:

                $rating_load $db->query_read("
                SELECT  p.postid, p.threadid, p.title, p.pagetext, r.*
                FROM " 
TABLE_PREFIX "erate AS r
                LEFT JOIN "
.TABLE_PREFIX."post AS p ON(p.postid = r.pid)
                WHERE r.rating = '"
.$rate_id."' AND r.uid = '".$user_id."' AND p.userid = '".$thisUser."'
                ORDER BY p.postid DESC
                "
); 

Only problem is that I actually need thread.title as opposed to post.title, but I would sitll like to keep post.pagetext.

Now how do I do a double LEFT JOIN to link all there of these into a single array, I need to be able to use the following variables to output them into HTML.

Quote:

thread.title, thread.threadid
post.pagetext, post.postid

I've made a little graphic representation of the 3 tables that I have. https://vborg.vbsupport.ru/external/2008/06/46.jpg


Thank you in advance.

Edit: This has been resolved, thanks!

Boofo 06-11-2008 01:55 AM

What is it exactly you are wanting to pull with the query? And why not just LEFT JOIN the thread table?

ZomgStuff 06-11-2008 02:06 AM

Because I still need the post.pagetext (which is the actual post content).

Basically I need to do a search by a "rating" type and "userid" , and be able to get the thread id, post id, post content, and thread title.

Would it just be simpler to do two separate LEFT JOIN's, one linking thread and the other post?

Boofo 06-11-2008 02:30 AM

That's the way I would go but I'm far from an expert on queries.

ZomgStuff 06-11-2008 02:37 AM

How would I be able to get the post conent. Would it be effcient to do two seperate LEFT JOIN's and then implode the two arrays?


--------------- Added [DATE]1213156014[/DATE] at [TIME]1213156014[/TIME] ---------------

I actually got the double LEFT JOIN query working, it was much easier that I thought.

Thanks for trying to help.

Finished product
https://vborg.vbsupport.ru/external/2008/06/45.jpg

Boofo 06-11-2008 04:23 AM

How does the query look now? I'm curious to see what you came up with.

Opserty 06-11-2008 10:58 AM

[sql]
SELECT p.postid, p.threadid, p.title, p.pagetext, r.*, t.threadtitle
FROM " . TABLE_PREFIX . "erate AS r
LEFT JOIN ".TABLE_PREFIX."post AS p ON(p.postid = r.pid)
LEFT JOIN ".TABLE_PREFIX."thread AS t ON(p.threadid = t.threadid)
WHERE r.rating = '".$rate_id."' AND r.uid = '".$user_id."' AND p.userid = '".$thisUser."'
ORDER BY p.postid DESC
[/sql]
I think that should work, not tested though. Might be a more efficient way of doing it but thats the way I would have done it ;)

ZomgStuff 06-11-2008 01:11 PM

Quote:

Originally Posted by Boofo (Post 1546374)
How does the query look now? I'm curious to see what you came up with.

[SQL] SELECT p.postid, p.threadid, p.pagetext, t.threadid, t.title, r.*
FROM " . TABLE_PREFIX . "erate AS r
LEFT JOIN ".TABLE_PREFIX."post AS p ON(p.postid = r.pid)
LEFT JOIN ".TABLE_PREFIX."thread as t ON(t.threadid = p.threadid)
WHERE r.rating = '".$rate_id."' AND r.uid = '".$user_id."' AND p.userid = '".$thisUser."'
ORDER BY p.postid DESC
[/SQL]


All times are GMT. The time now is 05:49 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01057 seconds
  • Memory Usage 1,738KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete