0

I'm using the Amazon Web Services API to interact with a SimpleDB domain. The relevant code is

selectExpression = "SELECT * FROM myDomain";

selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression)
                                         .WithNextToken(nextToken);
selectResponse = sdb.Select(selectRequestAction);

At this point I iterate through each returned line and do funky stuff. My table looks like this:

|  Name  |  AAA  | BBB | CCC  |
-------------------------------
| 519515 |  fox  | 311 | 1111 |
| 216165 |  cbs  | 971 | 1112 |
| 618105 |  nbc  | 035 | 1113 |
| 187655 |  npr  | 851 | 1114 |
| 551973 |  npr  | 654 | 1115 |
| 018583 |  cbs  | 302 | 1116 |
| 284801 |  www  | 762 | 1117 |

Basically I want to return all rows where AAA one of the top 5 AAA's. For instance, if there are:

  • 1000 rows where AAA is 'cbs'
  • 800 where AAA is 'elo'
  • 400 where AAA is 'npr'
  • 304 where AAA is 'www'
  • 200 where AAA is 'fox'

and

  • 100 where AAA is 'qwe'

I would like to return all rows where AAA is 'cbs', 'elo', 'npr', 'www', or 'fox'.

Thanks!

Mishap
  • 233
  • 4
  • 13

2 Answers2

0

What I am understand from your question, you need following output-

|  AAA  | 
---------
|  fox  |
|  cbs  |
|  elo  |
|  www  |
|  npr  |

for that you have to individually run these query-

select * from `myDomain` where `AAA` = 'cbs' order by `AAA` asc limit 1
select * from `myDomain` where `AAA` = 'fox' order by `AAA` asc limit 1
select * from `myDomain` where `AAA` = 'elo' order by `AAA` asc limit 1
select * from `myDomain` where `AAA` = 'www' order by `AAA` asc limit 1
select * from `myDomain` where `AAA` = 'npr' order by `AAA` asc limit 1
Ashish Pancholi
  • 4,569
  • 13
  • 50
  • 88
0

Once you have your top 5 values for the AAA attribute, you can use this query

select * from `myDomain` where `AAA` in('cbs','fox','elo', 'www', 'npr')

This will return all the rows where AAA is 'cbs', 'elo', 'npr', 'www', or 'fox'.

dcro
  • 13,294
  • 4
  • 66
  • 75