Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Question

Status
Not open for further replies.

JJ297

Programmer
Jun 27, 2007
30
US
Hi I'm a newbie and want to know if someone can help me to get the correct data out of my table. I've merged two tables but only want the topic listed one time and have the right questions and answers underneath those topics.

Here's my code:

select topics, questions, answer
from topics AS A, QuesNans AS B
where A.topicid = B.topicid
order by b.topicid

Thanks so much for any help anyone can give me.
 
Please show some sample data from the tables involved and expected results. This will most likely get you an acceptable solution quicker.

-George

"the screen with the little boxes in the window." - Moron
 
Okay thanks...

Here's my code:

select topics, questions, answer
from topics AS A, QuesNans AS B
where A.topicid = B.topicid
order by b.topicid

and here's the data

Topic One Question 1 Answer to question 1
Topic One Question 2 Answer to question 2
Topic Two Question 2 Answer to question 2
Topic Three Question 1 Answer to question 1
Topic Four Question 1 Answer to question 1

What I want is Topic One listed one time with both questions for topic one listed under Topic one. Don't want the heading Topic One (or other topics that have multiple questions underneath them) to display.

Thanks.
 
This should be handled in your data presentation layer (excel, access, whatever it may be).

SQL Server is not built to get data sets into funny (non-table) formats.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Good answer.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
But while we are onthe subject, you need to start using ANSI joins instead of the syntax
from topics AS A, QuesNans AS B
where A.topicid = B.topicid

This is an old syntax that is not supported in newer version of SQL server and if you try to write the equivalent of a left join this way you will get bad results as many times SQL Server 2000 will misinterpret it as a cross join instead of a left join.

This join sysntax is a bad habit that will require extensive rewrite of your system when you upgrade. You should avoid ever using it again.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top