Yes, sorry I didn't say "I know this isn't strictly Perl" -- I usually do.
To set the record straight, I am doing it in Perl, and for more detail of what I'm doing with DBI -- what the tables look like is more or less irrelevant, but essentially my select is:
select actor_name, episode_title, character_name
FROM <my tables>
WHERE <certain table columns match> AND actor_id = $id
And this results in rows representing a list of episodes an actor has appeared in. Most of the time he or she played the same character, so the character_name is the same in every row.
I wanted to be able to do a preliminary type of select which returned either one or more-than-one rows depending on whether that actor played one or more roles in total.
It does seem that GROUP BY will do what I want. Thanks.
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
| [reply] [d/l] [select] |
Slightly off topic... but since you mentioned it: PLEASE don't actually put literal values into your sql by string interpolation: $sql = "... thing_id = $thing_id ...";. Do it with placeholders and bind values. This can be more and less of a performance issue with different types of databases, but it is always a security issue.
In some databases, I could specify a $thing_id of "5; drop table thing", and you'd be hating life. On databases where that sort of thing can't be made to work (like oracle, for example), I could still plant a denial of service attack by saying that $thing_id was
"(select min(thing1.thing_id)
from
thing thing1,
thing thing2,
thing thing3,
thing thing4,
thing thing5,
thing thing6,
thing thing7,
thing thing8,
thing thing9,
thing thing10
--look! no 'where', clause this is a 10-way cartesian product of thin
+g!
)"
You can come back in a month when your database finishes processing that query.
------------
:Wq
Not an editor command: Wq
| [reply] [d/l] [select] |
Thanks for reminding me. I didn't understand the second example, but I sure as hell understood the first. I will certainly make sure that stuff is sorted out before the site becomes public.
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
| [reply] [d/l] |
I just wish I could lay my hands on the book where this was given as an example! Maybe if Cody read that he would find the answer?? | [reply] |