vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   simple select question (https://vborg.vbsupport.ru/showthread.php?t=101138)

sabret00the 11-19-2005 09:11 AM

simple select question
 
i have this query:
[sql] SELECT grps.groupid, grps.title, grps.create_date, grps.leaderid AS userid, grps_post.userid AS lastposter, grps_post.dateline AS lastpostdateline, COUNT( grps_post.userid ) AS replies
FROM grps_post
LEFT JOIN grps ON ( grps_post.groupid = grps.groupid )
GROUP BY grps_post.groupid
ORDER BY grps_post.dateline ASC
[/sql]

kinda, what i'm trying to make it do is SELECT the first row for the rest of the records, but the last row (i.e. the row with the highest dateline value) from the grps_post table along with the unique line from grps table, what am i doing wrong as i only seem to be able to retreive the first line?

i should know this, i'm pretty sure i do during the day time, but have no clue right now.

Marco van Herwaarden 11-19-2005 10:47 AM

[sql]SELECT grps.groupid, grps.title, grps.create_date, grps.leaderid AS userid, grps_post.userid AS lastposter, grps_post.dateline AS lastpostdateline, COUNT( grps_post.userid ) AS replies
FROM grps
LEFT JOIN grps_pst ON ( grps_post.groupid = grps.groupid )
GROUP BY grps.groupid
ORDER BY grps_post.dateline DESC LIMIT 1[/sql]If i understand you correct, you could try this.

sabret00the 11-19-2005 11:05 AM

that's still bringing up the first row from the grps_post table.

came up with this

[sql]SELECT grps.groupid, grps.title, grps.create_date, grps.leaderid AS userid, grps_post.userid AS lastposter, MAX( grps_post.dateline ) AS lastpostdateline, MAX( grps_post.pagetext ) , COUNT( grps_post.userid ) AS replies, MAX( grps_post.postid ) AS postid
FROM grps_post
LEFT JOIN grps ON ( grps_post.groupid = grps.groupid )
GROUP BY grps_post.groupid##, grps_post.postid

ORDER BY grps_post.dateline DESC [/sql]

is that bad sql?


All times are GMT. The time now is 03:52 PM.

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.00985 seconds
  • Memory Usage 1,708KB
  • 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)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