Let's use the example:
#!/bin/bash
ssh me@host "mysql -uuser -ppwd -t -e 'select * from mydb.mytable where id='$1''"
Note a problem: a single quote within a single quote of the command itself. I tried escaping it (\') - no luck, says "Unmatched '". Ideas?