vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Classic JOIN help (https://vborg.vbsupport.ru/showthread.php?t=51953)

filburt1 04-22-2003 01:12 AM

Classic JOIN help
 
I have two tables: mailmessage and mailfolder. This query works perfectly (returns the number of messages in each folder) except for when one folder doesn't have any messages.

I know I have to use a JOIN to solve this. How do I do it?
[sql]
SELECT mf.mailfolderid, mf.title, COUNT(mm.mailmessageid) AS messagecount
FROM mailmessage mm, mailfolder mf
WHERE mf.mailfolderid = mm.mailfolderid
AND mf.userid = 1 AND mm.userid = 1
GROUP BY mf.mailfolderid
[/sql]
If you want I can give a schema for both tables but you shouldn't need it, I think.

amykhar 04-22-2003 01:55 AM

looks like you are trying to code up competition for hivemail :D

Amy

filburt1 04-22-2003 01:56 AM

My mail system isn't planning to compete with it.

Ideas?

filburt1 04-22-2003 02:17 AM

I think I just coded a 53-line workaround that fetches all possible indicies, the ones the user has, and then diffs them. If it works? That's the question. :)

okrogius 04-22-2003 03:55 AM

try this:

SELECT mf.mailfolderid, mf.title, COUNT(mm.mailmessageid) AS messagecount
FROM mailfolder mf
LEFT JOIN mailmessage mm ON mailfolderid
WHERE mf.userid = 1 AND mm.userid = 1
GROUP BY mf.mailfolderid

Xenon 04-22-2003 07:34 PM

hmm, i think it would make problems, if it's empty and you are also asking for userids ....

try this:

[sql]SELECT mf.mailfolderid, mf.title, COUNT(mm.mailmessageid) AS messagecount
FROM mailfolder mf
LEFT JOIN mailmessage mm ON (mf.mailfolderid = mm.mailfolderid AND mm.userid = 1)
WHERE mf.userid = 1
GROUP BY mf.mailfolderid[/sql]

filburt1 04-22-2003 08:34 PM

No go, although my now-5-query workaround works.


All times are GMT. The time now is 03:07 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.01010 seconds
  • Memory Usage 1,714KB
  • 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
  • (7)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