Foreign Key references some

This is a discussion on "Foreign Key references some" within the Databases section. This forum, and the thread "Foreign Key references some are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 30th, 2008, 22:21
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Foreign Key references some

Is there anyway to have a column reference the amount of rows of another table based on a where?
Something like:
Code: Select all
create table tbl (
[columns here]
amount int(100) REFERENCES othertbl(COUNT(*) FROM othertbl GROUP BY column)
)
It's hard to explain what I mean, but that example should help.
Thanks.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 31st, 2008, 05:05
JustinStudios's Avatar
Reputable Member
Join Date: Mar 2007
Location: USA
Posts: 404
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Foreign Key references some

Alex, I actually did this with PHP... Not 100% sure if it is possible with just a SQL statement.

What I did was I selected the count from the table I wanted and then saved that to a variable, then I added that to the corresponding row in another table. So I used 2 SQL statements to do it really, just used PHP to hold the variable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 31st, 2008, 15:38
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Foreign Key references some

Yeah the point was that I didn't want to have to query twice.
If there's no way to do this on the mysql side I'll have to resort to two queries.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 31st, 2008, 17:05
JustinStudios's Avatar
Reputable Member
Join Date: Mar 2007
Location: USA
Posts: 404
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Foreign Key references some

The only way that I could fathom it could be done in one query is if you used a Select Into and somehow got it to return the count instead of the data. I've searched the internet for the answer and haven't found anything yet though. I'll keep playing around with it and if I find a solution I'll post it back.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jan 31st, 2008, 17:14
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Foreign Key references some

I guess I could just do select * from tbl, othertbl or some sort of left join anyway.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I design for a foreign language? mreine Web Page Design 6 Dec 28th, 2005 15:51
Foreign Key's adjacent, descriptive fields need updating - How To? jswebdev PHP Forum 0 Dec 10th, 2005 21:31


All times are GMT. The time now is 21:15.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42