tags:

views:

20

answers:

1

I have two tables. One table is named "Posts", the other is "Threads". Each of these has 3 columns named (id, author, content). The Posts table has a specific (thread) column. The thread column has to correspond to the id in the Threads table. What I'm trying to do is make one query that will select the thread, and all of its posts, and normalize its resulting fields. Here is what I want to generate:

author | content


Person| This is the thread's contents
Person| This would be a post.
Person| And another post.

A: 

"Normalize its resulting fields"? I'm not sure what you mean by that. Also you contradicted yourself saying both have three fields, but that Posts has a fourth field (foreign key to Threads)?

Also you really probably don't want to do that in one query (it would be far from "normalized"

SELECT * FROM Threads WHERE id = @id
SELECT * FROM Posts WHERE thread = @threads

Alternatively,

SELECT * FROM Posts LEFT JOIN Threads ON Posts.thread = Thread.id WHERE Posts.thread = @thread
smdrager
Not exactly what I was looking for. When I said normalizing I meant that both the threads content/author, and the posts content/author would have the same column name, but on separate rows.
Camoy