User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 426,024 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,698 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 2335 | Replies: 2
Reply
Join Date: Mar 2004
Posts: 732
Reputation: Phaelax is on a distinguished road 
Rep Power: 6
Solved Threads: 31
Phaelax Phaelax is offline Offline
Master Poster

static variables??

  #1  
Jun 21st, 2005
Is there a way I could create a variable that belongs to a table much like a static variable belongs to a class? So it "thing=1, person=2" were variables belonging to the table structure (not each row), then I could do something like this:

SELECT *
FROM table
WHERE type = table.thing OR type = table.person

I haven't touched sql in months, and I have a feeling this is something very simple.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: static variables??

  #2  
Jun 21st, 2005
I think I understand the functionality you are looking for. If not, I apologize now.
I've never seen anything like you described. This functionality is usually accomplished using what are commonly referred to as "Lookup Tables". A Lookup Table is usually a relatively small table with usually just 2 columns: an ID and a Name string. For example:
Manufacturer
===================
manufacturer_id BIGINT
manufacturer_name VARCHAR(50)

This table may contain data such as:
manufacturer_id manufacturer
=========================
1		Acura
2		Chevy
3		Ford
4		Honda
5		Toyota
Then your "car" table may look like this:
car_id manufacturer_id model_id year mileage color
================================================
1	 3		 2	 2004 24350 green
2	 3		 9	 2002 56771 black
3	 1		 34	 1999 78200 silver

See? Your car table uses the manufacturer_id instead of spelling out the manufacturer for every row. This is because, eventually your car table may have hundreds of thousands of rows, so why waste space inserting the manufacturer names in every row when there are only a handful of manufacturers.

So when you query, you do something like this:
SELECT manf.manufacturer_name
,mod.model_name
,c.year
,c.mileage
,c.color
FROM car c
INNER JOIN manufacturer manf ON c.manufacturer_id = manf.manufacturer_id 
INNER JOIN model mod ON c.model_id = mod.model_name
WHERE mileage < 50000
ORDER BY year DESC

This help?
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Mar 2004
Posts: 732
Reputation: Phaelax is on a distinguished road 
Rep Power: 6
Solved Threads: 31
Phaelax Phaelax is offline Offline
Master Poster

Re: static variables??

  #3  
Jun 23rd, 2005
I understand what you said, its how I ended up doing it anyway. I'm just used to thinking more along the lines of OOP (classes). Stupid Java!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 1:47 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC