vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   mysql troubles with left joins (https://vborg.vbsupport.ru/showthread.php?t=105329)

AN-net 01-14-2006 07:09 PM

mysql troubles with left joins
 
ok im trying to figure out a way to compare a table to another to find rows that no longer have a parent. similar to orphan thread but my only problem is that the column names are different but hold the same data. so the USE() function isnt possible and i do not think ON() will work because it will only find the rows that do coinside with table 1 from table 2. basically i want find journals that no longer have journalists and remove them.

sabret00the 01-14-2006 10:04 PM

what i'd personally do is run a high tensity script doing all the work in php.

PHP Code:

$users U_QUERY;
while (
$all_users $db->fetch_array(U_QUERY))
{
    
$current_users[] = $all_users['userid'];
}

$journals J_QUERY;

while (
$all_journals $db->fetch_array(J_USERS))
{
  if (!
in_array($all_journals['userid'], $current_users))
  {
    
$journals_to_be_deleted $all_journals['userid'] . ", ";
  }
}

// do delete query here 

something like that :)

AN-net 01-15-2006 01:08 PM

thanks for the suggestion but not what i was looking for ;)

sabret00the 01-15-2006 01:48 PM

Quote:

Originally Posted by AN-net
thanks for the suggestion but not what i was looking for ;)

i know but atleast it's something ;)

Paul M 01-15-2006 02:44 PM

Code:

SELECT * from table1
LEFT JOIN table2 ON (table1.column1 = table2.column2)
WHERE table2.column2 = NULL

Should find any entries in table1 that don't have a matching entry in table2 (column1 & column2 are the same data you referred to with different names in each table).


All times are GMT. The time now is 01:06 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.00983 seconds
  • Memory Usage 1,724KB
  • 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)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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