Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
bugbite
Starting Member
5 Posts |
Posted - 2004-11-24 : 04:06:38
|
| Hello all,I am returning eleven columns from two tables. My tables and columns are:EDITION - ISBN, Title, Sub_title, Publication_Date, No_of_pages, binding_code, short_blurb, long_blurb, reviewsPARTY - firstname, surnameThe link between the EDITION and PARTY tables is through two tables, AGREEMENT and ROLE.When I run my SQL statement it should return one row (when I add a where clause), but due to there being 2 agreements linked to this one title it is returning two rows instead as I need to go through AGREEMENT table to display the PARTY table details (I do not want to display any AGREEMENT details).My SQL code is:SELECT edition.ISBN, edition.title, edition.sub_title, party.first_name + N' ' + party.surname AS Name, edition.publication_date, edition.no_of_pages, edition.binding_code, edition.short_blurb, edition.long_blurb, edition.reviewsFROM edition INNER JOIN agreement ON edition.edition_id = agreement.edition_id INNER JOIN role ON agreement.role_id = role.role_id INNER JOIN party ON role.party_id = party.party_idI have tried to use GROUP BY which works fine if I display the following columns:ISBN, title, sub_title, publication_date, no_of_pages, binding_code, firstname, surnamebut if I try to also return the columns reviews, short_blurb and long_blurb I get the following error message:[Microsoft][ODBC SQL Server Driver][SQL Server]Column 'edition.short_blurb' is invalid in the select list because it is not contained in either an aggregate function or the group by clauseThe field properties for these three columns are ntext whilst the rest are a mixture of nvarchar, int & char.Any idea how I can get around this? |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-11-24 : 07:37:10
|
dare I ask why you jave two agreements then?you could always use TOPieSELECT Top 1 edition.ISBN, edition.title, edition.sub_title, party.first_name + N' ' + party.surname AS Name, edition.publication_date, edition.no_of_pages, edition.binding_code, edition.short_blurb, edition.long_blurb, edition.reviewsFROM edition INNER JOIN agreement ON edition.edition_id = agreement.edition_id INNER JOIN role ON agreement.role_id = role.role_id INNER JOIN party ON role.party_id = party.party_id--Where blah blah Corey |
 |
|
|
|
|
|
|
|