Jump to content

[SOLVED] Bringing 3 tables together


peddel

Recommended Posts

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.