2

I have a simple table

amps | 120-240 | 120-208 | 277-480
__________________________________

10   |  $99.00  | $149.00 | $344.00

20   | $199.00 | $298.00 | $688

I want a query something like this but I can't get it to work ...

select * from `table` where amps like '10' and column_name like '120-208';

or

select * from `table` where amps like '20' and column_name like '277-480';

Please Help! Maybe I am overlooking an easier way to set this up?

Thanks!

Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
user3100370
  • 39
  • 1
  • 1
  • 4

1 Answers1

4

Just like this?

SELECT `120-208` FROM table WHERE amps = '10'
Marc
  • 924
  • 1
  • 8
  • 18
  • 2
    If the numeric values are really column names, it should be `SELECT \`120-208\` FROM` – feeela Mar 19 '14 at 15:42
  • `[...]` is Sybase notation. `\`...\`` is MySQL. – tadman Mar 19 '14 at 15:44
  • That throws me an error ... I just need to get the $ cost for amps where the column name equals one of those voltages. – user3100370 Mar 19 '14 at 15:45
  • You are both correct ... I used Marc's statement with tadman's syntax and it works perfectly! Thanks – user3100370 Mar 19 '14 at 15:49
  • No worries. Apologies, I'm from a TSQL background, not MySQL so my mistake on the square-bracket syntax. Glad it helped though. Updated my answer accordingly. – Marc Mar 19 '14 at 17:32
  • FYI, both MySQL and Microsoft/Sybase use non-standard delimiters. See my answer to https://stackoverflow.com/a/214344/20860 – Bill Karwin Dec 23 '19 at 18:20