Welcome Guest, Not a member yet? Register   Sign In
Mysql Join Table help
#1

[eluser]help_123[/eluser]
Question:

I have two tables table 1 and table 2 ;
Table1: Table2:
pid lname fname mid age
12 Gary Moore 24 67
14 kate Lindsay 25 16
45 masaa Raffi 27 44
56 ham burg 30 10

pid and mid are primary keys for both tables.
as you can see both tables have unique primary keys and cannot be join through regular join.

Is there a MYSQL query where i can join table like this(I have just added age column from second table to first table as it is))?:
pid lname fname age
12 Gary Moore 67
14 kate Lindsay 16
45 masaa Raffi 44
56 ham burg 10

Waiting for response...i am specificily lookng mysql query
#2

[eluser]JWarren[/eluser]
Is there a reason you have that in two tables? If there is a one to one relationship, I would definitely combine the tables.
#3

[eluser]help_123[/eluser]
[quote author="JWarren" date="1259375362"]Is there a reason you have that in two tables? If there is a one to one relationship, I would definitely combine the tables.[/quote]

yes..it got messed up somehow..it is one to one relationship...do u know the mysql query way to combine it..coz i have huge amount of data like dat....can u help me out
#4

[eluser]jedd[/eluser]
[quote author="help_123" date="1259372702"]
I have two tables table 1 and table 2 ;
Table1: Table2:
pid lname fname mid age
12 Gary Moore 24 67
14 kate Lindsay 25 16
45 masaa Raffi 27 44
56 ham burg 30 10
[/quote]

It might be possible to describe a pair of database tables in a less meaningful way .. but it'd take some serious effort.

Can you please hop into your mysql CLI and type the following, capture the output, and post in [ code ] tags:
Code:
mysql>  describe table_1;
mysql>  describe table_2;

You've described some sample data - this is good. Describe what data structure you are looking for to come out of the SQL query - using the same sample data set.
#5

[eluser]help_123[/eluser]
[quote author="jedd" date="1259381573"][quote author="help_123" date="1259372702"]
I have two tables table 1 and table 2 ;
Table1: Table2:
pid lname fname mid age
12 Gary Moore 24 67
14 kate Lindsay 25 16
45 masaa Raffi 27 44
56 ham burg 30 10
[/quote]

It might be possible to describe a pair of database tables in a less meaningful way .. but it'd take some serious effort.

Can you please hop into your mysql CLI and type the following, capture the output, and post in [ code ] tags:
Code:
mysql>  describe table_1;
mysql>  describe table_2;

You've described some sample data - this is good. Describe what data structure you are looking for to come out of the SQL query - using the same sample data set.[/quote]

nothing as such as long as i can combine both tables with mysql query like this(based on example described above):

pid lname fname age
12 Gary Moore 67
14 kate Lindsay 16
45 masaa Raffi 44
56 ham burg 10
#6

[eluser]jedd[/eluser]
Hmmm. Can you please describe the two source tables .. properly?

It looks like you have two completely unrelated sets of data that you want to somehow join, despite there being no logical connection between the two sets.

Is that right?

Are you just trying to join the first row of one table with the first row of another table, and then repeating that for every row in the two tables?

Do you know what the R in RDBMS stands for?
#7

[eluser]help_123[/eluser]
[quote author="jedd" date="1259382750"]Hmmm. Can you please describe the two source tables .. properly?

It looks like you have two completely unrelated sets of data that you want to somehow join, despite there being no logical connection between the two sets.

Is that right?

Are you just trying to join the first row of one table with the first row of another table, and then repeating that for every row in the two tables?

Do you know what the R in RDBMS stands for?[/quote]

You got it right everything.
Its relational Database management system..i just know by definition...i am looking for mysql query form to combine this data.
#8

[eluser]jedd[/eluser]
This is surreal.

What are the primary keys on these two tables? From my understanding, the order of delivery of data from a RDBMS is not guaranteed, absent an ORDER BY clause, and with your ID fields not matching, I'm guessing they don't necessarily match row-by-row between the two tables, either?

How many rows do you have, btw?

I can't think of any SQL way of doing this - but I'm no SQL guru - so you might have to pull these data into PHP and combine them there, and pump them back out to whatever source (.csv, txt, or back to SQL) that you want.

How sure you are that when you select * from each of the two tables, that the results actually do align with each other? I mean, given there's no way to correlate the two separate sets of data, there's no visual clues as to whether gary is 45 with a surname of moore and a mid of ... etc.

Actually, in what way do you believe this is related to CodeIgniter?




Theme © iAndrew 2016 - Forum software by © MyBB