PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 13th, 2003, 11:16 AM
msc27jxg msc27jxg is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 msc27jxg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Please help with a query!

These are my tables:

pid | name
1 A
2 B
3 C
4 D
5 E

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!!

Many Thanks!!

Joe

Reply With Quote
  #2  
Old July 14th, 2003, 02:42 PM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 58 sec
Reputation Power: 17
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
Hey Joe,

First off are you sure you want to set your tables up like that?

Wouldn't it be better to have

pid_table:
pid | name

tid_table:
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.

HTH
-b


**EDIT**
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.
__________________
PostgreSQL, it's what's for dinner...

Last edited by bcyde : July 14th, 2003 at 02:44 PM.

Reply With Quote
  #3  
Old July 15th, 2003, 08:09 AM
msc27jxg msc27jxg is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 msc27jxg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

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.

Regards,

Joe

Reply With Quote
  #4  
Old July 16th, 2003, 04:38 PM
cgi bin laden cgi bin laden is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 4 cgi bin laden User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 25 sec
Reputation Power: 0
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:

players p

teams t

playerteams pt

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Please help with a query!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap