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
Old 03-03-2003, 09:19 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
sql question .. joining 3 tables

i'm trying to make a tutorial viewer for codenewbie and i need to do a fancy join. i'm not 1337 with sql yet.. so i ask you here:

this is the table structure of the tables and fields i need to use:
Code:
 forum:  forumid,forum_title
thread:  threadid,forumid
   post:  postid,threadid,post_title
i need to select forum_title in my post query .. this is not right, but this is what i need to do:
Code:
select postid,post_title,forum_title from post;
i have to use the thread table to referrence the threadid to then referrence the forumid to get the forum name from the forum table.
sde is offline   Reply With Quote
Old 03-03-2003, 09:34 AM   #2 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
select forum.forumid, forum.title, thread.threadid, thread.forumid, post.postid, post.threadid, post.title from forum, thread, post where post.threadid = thread.threadid and thread.forumid = forum.forumid and post.postid = 'ID_HERE';

that what you need?

that might be wrong, ugh. ill test it again.
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 03-03-2003, 09:37 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
i'll let you know in a bit .. looks like it though.. thanks!
sde is offline   Reply With Quote
Old 03-03-2003, 09:37 AM   #4 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
test it out and let me know if it works right. it seems to be working properly.
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 03-03-2003, 11:53 AM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
select forum.title, post.postid, post.title, post.username, post.dateline from forum, thread, post where post.threadid = '$each' and thread.threadid='$each' and thread.forumid = forum.forumid and post.visible='1' order by post.postid asc limit 1

here's where i'm at .. $each is the threadid array that i'm looping through. this query isn't working .. still trying to debug.
sde is offline   Reply With Quote
Old 03-03-2003, 12:44 PM   #6 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
your query is failing because you don't have a valid join in your statement. the sql parser doesn't understand that it needs to join on threadid. this will probably work better

Code:
select
  forum.title,
  post.postid,
  post.title,
  post.username,
  post.dateline
from 
  forum,
  thread,
  post
where
  post.threadid='$each' and
  thread.threadid=post.threadid and
  thread.forumid=forum.forumid and
  post.visible='1'
order by
  post.postid asc
limit 1
joe_bruin is offline   Reply With Quote
Old 03-03-2003, 12:44 PM   #7 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
where are you getting the value of $each?

what errors are you getting?
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 03-03-2003, 01:08 PM   #8 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
PHP Code:
select
    post
.*,
    
forum.forum_title
from
    posts
inner join
    thread on thread
.threadid post.threadid
inner join
    forum on forum
.forumid thread.forumid
where
    postid 
10 
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 03-03-2003, 01:12 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
thanks guys. it was a combination of the source of my $each and my lack of sql 1337-ness.

it's working .. now i can move on.
sde is offline   Reply With Quote
Reply

Bookmarks

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
DB Design Question Part II sde Program Design and Methods 3 05-10-2003 12:24 PM
Database Design Question sde Program Design and Methods 7 04-25-2003 05:55 PM
SQL Server Worm -- Is It Just Me.... technobard Lounge 6 01-30-2003 02:53 PM
loading sql schema from php sde PHP 7 12-11-2002 06:57 PM


All times are GMT -8. The time now is 05:12 AM.


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





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting