| Author |
Topic |
|
sedwick1024
Starting Member
6 Posts |
Posted - 2007-02-06 : 12:46:44
|
| I am trying to find mulitple records that have the same set of values in two columns. For example, in a Books table with Author and Genre columns, I want to return all records that share the same Author and Genre. If I had the following records:_Author_ _Genre_Bradbury DramaBradbury Science FictionClancy SuspenseSteele RomanceBradbury Science FictionClancy SuspenseSteele AutobiographyBradbury Science FictionSteele RomanceClancy DramaBradbury RomanceI'd want the following results:_Author_ _Genre_Bradbury Science FictionClancy SuspenseSteele RomanceYour help is graciously appreciated in advance.--Sedwick |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-06 : 13:10:31
|
| select author, max(genre) from table1 group by authorPeter LarssonHelsingborg, Sweden |
 |
|
|
sedwick1024
Starting Member
6 Posts |
Posted - 2007-02-06 : 13:30:25
|
| Eh, not quite. I don't want to limit it to the most matches per Author, as an author may have done multiple works in another genre as well, something I apologize for not making clear. If I had multiple records with these values:_Author_ _Genre_Bradbury ComedyI'd want that to also show up with the sample results I gave.--Sedwick |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-06 : 14:06:13
|
My suggestion do not return the "most matches". It returns the MAX genre (alphabetically) for each author.This query, however, returns all multiples in the books table.SELECT author, genrefrom Books group by author, genre having count(*) > 1 Peter LarssonHelsingborg, Sweden |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
sedwick1024
Starting Member
6 Posts |
Posted - 2007-02-06 : 15:00:26
|
| There's only one record that has Bradbury as the author and Drama as the Genre. Meanwhile, there are 3 records that have Bradbury as the author and Science Fiction as the Genre, so it would show up.--Sedwick |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
sedwick1024
Starting Member
6 Posts |
Posted - 2007-02-06 : 15:38:39
|
| No, it's for jobwork. I just need to know which author/genre combinations show up in multiple records. Peso's last post seems to have done it though, so thanks!--Sedwick |
 |
|
|
|