Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have two tables

Name-fields(username,age)
Type-fields(gender)


These are my two tables and i want to copy these data and merge them into a new separate table like this using sqlite3

output table-fields(username,age,gender)

make me out of this question

What I have tried:

i have tried update method but did not got an clear output
Posted
Updated 13-Aug-18 2:10am
Comments
CHill60 13-Aug-18 7:26am    
You have nothing to link the two tables together
Ruban Bharath 13-Aug-18 7:33am    
okay kindly tell me that what is the procedure to join these tables sir.Thank you in advanced
CHill60 13-Aug-18 7:38am    
The only way you can join these tables is by a cross join - meaning that for each username + age combination you will get two rows, one for male and one for female.
Your design is faulty.
Ruban Bharath 13-Aug-18 7:43am    
no sir this is actually not my original design but i need to know how to join two tables into one sir,but the concept is same i have two tables with different fields i wanna join them but i have tried but it emerges an error
i got struct in it for an whole day sir

1 solution

In general, if you want to join tables then you have to have some column in common between the tables. See SQL Joins Explained[^]

In your case you have no columns in common so the only join you can have is a cross-join - SQL Cross Join[^]
SQL
select * from [Name], [Type]
To fix this, your table structures should be
SQL
Name-fields(username,age,genderid)
Type-fields(genderid, gender)
E.g.
UserName   GenderId
username1   1
username2   2
username3   1
GenderId Gender
1        Female
2        Male
and you can then use something like this
SQL
select username, age, gender
from [Name] N
left join [Type] T ON N.genderid=T.genderid
 
Share this answer
 
Comments
Ruban Bharath 14-Aug-18 0:39am    
sir, i have tried your code but it shoots me this error
ambiguous column name: genderId
CHill60 14-Aug-18 4:20am    
Have you typed the code exactly as I put it in the solution ... I have qualified each use of genderid in my solution - i.e.
left join [Type] T ON N.genderid=T.genderid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900