Click here to Skip to main content
16,015,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all i need to retrive data from two differenet table like an one table, and the two table doesnot have any same columns, and the data must not allowed duplictes i tried but not getting output exactly
Posted
Updated 19-Jul-14 2:11am
v2
Comments
[no name] 19-Jul-14 8:16am    
And you expect us to do what based on this information? We have no idea at all what it is that you have tried, what your data base tables look like, what data you have, what your output is or what you expect the output to be.

If your two tables do not have any "same columns" then there is nothing connecting the rows in the two tables - so you can't retrieve data from them both at the same time - there has to be a column which connects them. Normally, this would be an ID column which says "these rows in Table 2 are associated with this row in Table 1".
If you don't have that kind of data, then you can't do what I assume you want.

Think about it: If this is an online shop, then you probably want to prevent me accidentally ordering the same thing twice by clicking the "BUY" button twice. So you would check that my id does not contain an order for today which contains the same items to prevent duplicates. But my neighbour can place an order for the same items I did because he has a different ID, so my order items aren't associated with him.
If you don't have that kind of information, then you need to look at your database design pretty carefully.
 
Share this answer
 
Comments
Muthuraj.M 23-Jul-14 5:15am    
Thank you OriginalGriff
OriginalGriff 23-Jul-14 5:31am    
You're welcome!
One fundamental concept of relational database like sql server is about establishing relationship between tables, suggest you read this article to learn more: Fundamentals of Relational Database Design[^]
 
Share this answer
 
Comments
Muthuraj.M 23-Jul-14 5:15am    
thank your for ur guideline Peter Leow
Peter Leow 23-Jul-14 6:19am    
You are welcome.
You should make a view which contains this two tables.Then make a relationship between the columns that have not the same names(make inner join).Then select the columns that you want.
 
Share this answer
 
Comments
Muthuraj.M 23-Jul-14 5:16am    
thank you maliheSadat
maliheSadat 25-Oct-14 8:16am    
you are welcome.
I think you can go for Cross join so that you no need to have a common column. You can follow like this
SQL
Select distinct * from Students cross join Teacher

SQL
Select distinct * from Students,Teacher

But without relation between two tables is not a good.
 
Share this answer
 
Comments
Muthuraj.M 23-Jul-14 5:16am    
Thank you
By Creating View You Can Retrieve data from one are more tables
 
Share this answer
 
Comments
Muthuraj.M 23-Jul-14 5:16am    
thank you nayeem
nayeem@codeproject 7-Aug-14 3:09am    
welcome

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