vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Pulling a specific number of threads from each forum.. can it be done in one query? (https://vborg.vbsupport.ru/showthread.php?t=63930)

djnoz 04-15-2004 11:43 PM

Pulling a specific number of threads from each forum.. can it be done in one query?
 
What I need to do, is write a query that pulls the latest 4 threadids out of a specified list of forumids individually.

So basically, if I was specifying forumids 1 and 2, the query would display two lists of the four latest threadids from those forums.

The output at the mysql console would look something like this

Code:

Forumid        |Threadid
1        |12
1        |11
1        |9
1        |7

2        |13
2        |10
2        |8
2        |6

Is this possible, or must I run multiple queries?

Thanks :)

Velocd 04-17-2004 04:30 AM

PHP Code:

SELECT 
FROM thread 
WHERE forumid IN 
($forumid_list
ORDER BY dateline 
LIMIT 4 

This is what you need, if I understood you correctly.

djnoz 04-17-2004 05:56 AM

The problem with that query is that I want the 4 latest threads from each forum... that query takes the 4 latest threads aggregated together from both forums.

If two forums are specified, the query should return 8 values - 4 threads from the first forum, and 4 threads from the second forum. I haven't been able to figure out how to do this without running a seperate query for each forum.

Thanks for the reply anyway. ;)


All times are GMT. The time now is 08:25 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.00968 seconds
  • Memory Usage 1,711KB
  • 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_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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