The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
![]()
I want to do the following two thing:
1- Select all posts (with its information) belong to one thread something like: PHP Code:
2. For each posts (each row), there is one userid, I need to select all awards that belong to that userid something like PHP Code:
if I run query #2 for each of the rows, it will run 15 times, + 1 query for #1, is there any way to optimize the queries? so that I can somehow get a list of awards for each userid. |
#2
|
||||
|
||||
![]()
Untested:
[sql] SELECT post.* awards.* FROM " . TABLE_PREFIX . "post as post LEFT JOIN post ON post.userid = award.userid [/sql] You didn't give any info on your db schema for the awards table so I'm afraid I can't be of much help other than the query above which may or may not work depending what you have in the awards table ![]() |
#3
|
||||
|
||||
![]() Quote:
![]() The db schema is available in my new hack https://vborg.vbsupport.ru/showthread.php?t=78934 PHP Code:
|
#4
|
|||
|
|||
![]()
You really should use the LEFT JOIN like Dean showed you.
Also you will need to add an AS to the FROM clauses: [sql]" . TABLE_PREFIX . "post AS post[/sql] Or things will go wrong if a table prefix is used. |
#5
|
||||
|
||||
![]()
Dean's left join won't work, as it would just select ONE award per post.
you have two possibilities: 1) put both tables into the from tag 2) cache the results of query two with one big query, and then work with the cache |
#6
|
||||
|
||||
![]() Quote:
https://vborg.vbsupport.ru/showthread.php?t=78934 Thank you very much ![]() |
#7
|
||||
|
||||
![]() Quote:
says LEFT JOIN post ON (userid) and LEFT JOIN post USING (userid) |
#8
|
||||
|
||||
![]()
using just allows a column-name, ON instead allows more complex conditions like for example:
[sql]SELECT * FROM post LEFT JOIN user ON (user.userid = post.userid * 2)[/sql] or whatever (not that the statement above would be usefull ![]() |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|