944,153 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 3485
  • MySQL RSS
Jun 21st, 2005
0

static variables??

Expand Post »
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.
Similar Threads
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Jun 22nd, 2005
0

Re: static variables??

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:
MySQL Syntax (Toggle Plain Text)
  1. Manufacturer
  2. ===================
  3. manufacturer_id BIGINT
  4. manufacturer_name VARCHAR(50)

This table may contain data such as:
MySQL Syntax (Toggle Plain Text)
  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:
MySQL Syntax (Toggle Plain Text)
  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:
MySQL Syntax (Toggle Plain Text)
  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?
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jun 23rd, 2005
0

Re: static variables??

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!
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: mysql sortieren
Next Thread in MySQL Forum Timeline: MySql multiple table query problem....





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC