Jump to content


Photo

Using Joins...


  • Please log in to reply
4 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 March 2006 - 02:28 PM

If I had two tables:

Table A has some records that B doesn't

Table B has some records that A doesn't

I can do JOIN on FIELD1

I want ALL records...

Can't do left, can't do right... for obvious reasons...

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 13 March 2006 - 02:36 PM

you can do a simple query and join the records in the WHERE clause:
SELECT * FROM table1 a, table2 b WHERE a.field1 = b.field1;

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 March 2006 - 05:53 PM

That won't do it because if A exists and B doesn't you won't get A and vice versa...
[!--quoteo(post=354504:date=Mar 13 2006, 09:36 AM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 13 2006, 09:36 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you can do a simple query and join the records in the WHERE clause:
SELECT * FROM table1 a, table2 b WHERE a.field1 = b.field1;
[/quote]


#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 13 March 2006 - 06:11 PM

[!--quoteo(post=354586:date=Mar 13 2006, 12:53 PM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 13 2006, 12:53 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
That won't do it because if A exists and B doesn't you won't get A and vice versa...
[/quote]

ah, i see what you're saying. did you try OUTER JOIN?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 March 2006 - 06:36 PM

Let me try outer joins... I've never used it... but this is a common problem for me..

THANKS!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users