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 t开发者_JAVA技巧o 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."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
精彩评论