peddel Posted February 3, 2009 Share Posted February 3, 2009 Hello, I got a problem with bringing 3 tables together. This is the situation : Table 1 : int type ID | RegistrationID | Tag | Value Table 2 : float type ID | RegistrationID | Tag | Value Table 3 : string type ID | RegistrationID | Tag | Value I made these three tables because of the type that is used in the value option. I wanna seperate int values from floats. Now i wanna ask questions on all my data, but for that i need to place the data in a temporary tabel, all together. I hope someone understands my problem. So i need to find a query that places all the elements together in a table with the same collumns, if that is even possible. Quote Link to comment https://forums.phpfreaks.com/topic/143578-solved-bringing-3-tables-together/ Share on other sites More sharing options...
menwn Posted February 3, 2009 Share Posted February 3, 2009 Hello there, I am not sure why you have used 3 tables. A varchar field should be able to host all three kinds of values (int, float and string). So a good solution would be to just modify the value field to varchar. And execute select queries easily. Now if you HAVE to have them separated I would suggest a join query, or even simpler a where-and query, like the following example: Select * from table1, table2, table3 where table1.FIELD = WHATEVER and table2.FIELD = WHATEVER and table3.FIELD = WHATEVER WHATEVER could be even a field of another table (in the form tablex.FIELD) or a number, string etc. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/143578-solved-bringing-3-tables-together/#findComment-753366 Share on other sites More sharing options...
peddel Posted February 3, 2009 Author Share Posted February 3, 2009 Well for a starter, im a program student who is making something called an "eindwerk" in Belgium. So i know what im doing concerning the 3 tables since making it a varchar is like kinda dumb. The elements need to get calculations on them and i dont like typecasting them every single time to an int or a float. Nevertheless i found the option i was looking for, namely the UNION query. It seems that this piece of code does what i wanted. (SELECT * FROM registratie_float_waarden) UNION (SELECT * FROM registratie_int_waarden) UNION (SELECT * FROM registratie_string_waarden) Quote Link to comment https://forums.phpfreaks.com/topic/143578-solved-bringing-3-tables-together/#findComment-753369 Share on other sites More sharing options...
menwn Posted February 3, 2009 Share Posted February 3, 2009 First of all being a program (sic) student apparently does not help you much in expressing correctly your problem in a PHP post. As a program (sic) student I am sure you already know that in PHP you do not declare data types in variables. So it's the same either you have $variable = 'program student'; or $variable = '2'; Also what's dumb is to create three different tables and therefor use a UNION or JOIN query(!!!!) which are much more heavier. If you want two avoid varchar you should really change your PHP code to accommodate three different fields in the same table. Haven't anyone told you about something called database normalization? Finally a couple of tips for the future: Be more polite to people who try to help you. Learn now to use and love varchar fields as in the industry you will learn it the hard way when an int data field has been used where a varchar should have been used instead. Quote Link to comment https://forums.phpfreaks.com/topic/143578-solved-bringing-3-tables-together/#findComment-753393 Share on other sites More sharing options...
peddel Posted February 3, 2009 Author Share Posted February 3, 2009 I am sorry but i did not intend to atack you in any way. Explaining my problem in englisch isnt that easy, since i am used of speaking dutch. The reason behind the different fields has started when i made my database without even having 1 idea about normalisation. When my teacher pointed out that databases are best normalized i tried to but got stuck in some situation. I cant explain my whole project just here, but there tons of reasons why i have choosen to use 3 tables. As i have used varchar before to store ints and such i know its no problem and can be done. And im in need of JOINS, VIEWS and UNIONS to solve all of my programming code ^^. I know they are tough but im learning by falling and getting back up. Again i apolagise if i offended u in any way. Quote Link to comment https://forums.phpfreaks.com/topic/143578-solved-bringing-3-tables-together/#findComment-753403 Share on other sites More sharing options...
menwn Posted February 4, 2009 Share Posted February 4, 2009 OK no problem there. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/143578-solved-bringing-3-tables-together/#findComment-754356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.