Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...)
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 04-23-2007, 06:45 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
join help

table: n
n_id
text

table: f
f_id
n_id

table: a
f_id
title


i need to join these 3 tables but i'm having trouble. i get null data in the field's i'm requesting from table a.

Code:
select n.text, a.title from n left join f on n.n_id=f.n_id left join a on a.f_id=f.f_id
for suggestions, assume there is one record in each table with table f associating tables n and a.

any help would be appreciated.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 04-24-2007, 01:05 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
Code:
select n.text, a.title, f.f_id from n, f left join a on a.f_id=f.f_id where n.n_id=f.n_id
Some databases need the relation in the select.
The "inner join" of n+f makes sure that both n and f exist
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 04-24-2007, 11:57 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
thanks djm.. i saw this last night but 2am was too late to give it a shot.

i got it working today and i get 3 rows for every one completely related record. for example
Code:
+-----+------------+------------+-------------+---------+-------+ | nid | body | created | title | artist | album | +-----+------------+------------+-------------+---------+-------+ | 32 | test | 1177359050 | NULL | NULL | NULL | | 32 | test | 1177359050 | NULL | NULL | NULL | | 32 | test | 1177359050 | mytitle | myartist | myalbum |
i just added 'title is not null' to the where clause and i get the set i'm looking for.

thanks.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JOIN Syntax Help transfield PHP 3 05-25-2006 08:41 AM
sql / php elohmrow PHP 8 11-15-2005 06:21 PM
Hacking your Linksys WRT54G sde Linux / BSD / OS X 18 04-20-2005 03:37 PM
Left outer join problem snauw Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 02-01-2005 10:39 PM
SQL Query Help Please sde Program Design and Methods 6 03-07-2004 10:48 AM


All times are GMT -8. The time now is 09:36 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle