July 13th, 2003, 11:16 AM
Please help with a query!
These are my tables:
pid | name
tid | pid 1 | pid 2 | pid 3
1 1 2 3
Bascially, I would like to write a query to list only the names which their "pid" match those pids in the other table. If anyone knows, pls help!!
July 14th, 2003, 02:42 PM
First off are you sure you want to set your tables up like that?
Wouldn't it be better to have
pid | name
tid | pid
This way you won't be limited to only 3 pids for each tid.
Then you can just do a SELECT tid, name FROM pid_table, tid_table WHERE pid_table.pid = tid_table.pid .
If you want to limit the max number of matches for pids to tids you can use a plpgsql function to enforce this.
Hmm, looking at your question again, I'm not sure if I addressed it correctly, if not please let me know and just restate what you're asking so I can understand it better.
Last edited by bcyde; July 14th, 2003 at 02:44 PM.
PostgreSQL, it's what's for dinner...
July 15th, 2003, 08:09 AM
Sorry if I confused you. 'pid' stand for playerID and 'tid' stand for teamID and so the set up of those tables are necessary. Each team has a number of players selected from the player table.
Anyway I have solved the problem but thanks for your suggestion.
July 16th, 2003, 04:38 PM
bcyde is correct
You still should set up your tables differently, if only to get into the habit of doing so.
I recently built a very large, very complex system for team/player management.
The way I did it was:
where pt.player_id = p.id and pt.team_id = t.id
This gives you the ability to have mutliple players on multiple teams and much less redundancy or repetition of data entry.
Just a thought