static variables??

Reply

Join Date: Mar 2004
Posts: 802
Reputation: Phaelax is on a distinguished road 
Solved Threads: 40
Phaelax Phaelax is offline Offline
Practically a Posting Shark

static variables??

 
0
  #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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: static variables??

 
0
  #2
Jun 22nd, 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:
  1. Manufacturer
  2. ===================
  3. manufacturer_id BIGINT
  4. manufacturer_name VARCHAR(50)

This table may contain data such as:
  1. manufacturer_id manufacturer
  2. =========================
  3. 1 Acura
  4. 2 Chevy
  5. 3 Ford
  6. 4 Honda
  7. 5 Toyota
Then your "car" table may look like this:
  1. car_id manufacturer_id model_id YEAR mileage color
  2. ================================================
  3. 1 3 2 2004 24350 green
  4. 2 3 9 2002 56771 black
  5. 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:
  1. SELECT manf.manufacturer_name
  2. ,MOD.model_name
  3. ,c.YEAR
  4. ,c.mileage
  5. ,c.color
  6. FROM car c
  7. INNER JOIN manufacturer manf ON c.manufacturer_id = manf.manufacturer_id
  8. INNER JOIN model MOD ON c.model_id = MOD.model_name
  9. WHERE mileage < 50000
  10. 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 Quick reply to this message  
Join Date: Mar 2004
Posts: 802
Reputation: Phaelax is on a distinguished road 
Solved Threads: 40
Phaelax Phaelax is offline Offline
Practically a Posting Shark

Re: static variables??

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2830 | Replies: 2
Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC