•
•
•
•
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
![]() |
•
•
Join Date: Mar 2004
Posts: 732
Reputation:
Rep Power: 6
Solved Threads: 31
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.
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.
•
•
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation:
Rep Power: 4
Solved Threads: 4
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:
This table may contain data such as:
Then your "car" table may look like this:
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:
This help?
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
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?
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- static variables in python (Python)
- Static Variables: (C++)
- How do I go about viewing static variables while debugging? (C++)
- HELP: class static function - compile errors (C++)
Other Threads in the MySQL Forum
- Previous Thread: mysql sortieren
- Next Thread: MySql multiple table query problem....


Linear Mode