| | |
static variables??
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2004
Posts: 802
Reputation:
Solved Threads: 40
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.
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:
MySQL Syntax (Toggle Plain Text)
Manufacturer =================== manufacturer_id BIGINT manufacturer_name VARCHAR(50)
This table may contain data such as:
MySQL Syntax (Toggle Plain Text)
manufacturer_id manufacturer ========================= 1 Acura 2 Chevy 3 Ford 4 Honda 5 Toyota
MySQL Syntax (Toggle Plain Text)
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
So when you query, you do something like this:
MySQL Syntax (Toggle Plain Text)
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?
![]() |
Similar Threads
- How do I go about viewing static variables while debugging? (C++)
- static variables in python (Python)
- Static Variables: (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....
Views: 2830 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for MySQL
"use" 1 agplv3 alfresco amazon api artisticlicense breathalyzer camparingtocolumns changingprices cmg contentmanagement count court crm data database design developer development drupal dui ec2 eliminate email enter enterprise error eudora facebook form foss gartner gnu government gpl greenit groklaw groupware images innerjoins insert ip joebrockmeier join journalism keywords laptop law legal license licensing linux maintenance managing matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource operand oracle pdf penelope php priceupdating referencedesign remove reorderingcolumns resultset saas select sharepoint sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency update virtualization





