|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Unique id's
HI there
![]() I'm not sure how to explain this, but here it goes. I have 2 forms, A and B, with few different fields, and a administration Aa and Bb. So what I want is to join Aa and Bb. In my former thread: Table INNER JOIN I succeeded joining Aa and Bb, but I encountered a problem since submitted forms A and B have independent ID's and don't take 'consideration' to each others ID numbers. I mean ID numbers overlap. So how do I do to give them unique ID's? Did it make sence ? |
|
#2
|
||||
|
||||
|
I'm not exactly sure what problem you are trying to solve.
1. Is the problem that you have 2 tables that have some data in common and some fields not in common and you want to see all the data? For example: tableA firstName LastName Phone tableB FirstName LastName Address city state any you want to see: firstname, lastname, phone, address, city, state 2. You have 2 tables that have similar data structures (fields that are common to both) but different data sets and you want to see all of the data? For example: table A FirstName, LastName Barney, Rubble Fred, Flintstone table B FirstName, LastName Harry, Potter Ron, Weasley and you want: FirstName, LastName Barney, Rubble Fred, Flintstone Harry, Potter Or is it something else? A small sample of what you have and what you want will help. Ron, Weasley |
|
#3
|
|||
|
|||
|
What I want is something like option 2
Table A: ID: is not something you can fill in but a number that automatic ascends with the number of forms submitted. Subject: fill in Date: submitted Table B: ID: is not something you can fill in but a number that automatic ascends with the number of forms submitted. Subject: fill in Date: submitted Administration of A and B ID Subject Date 1 tableA xx-xx-xx 1 tableB xx-xx-xx So the conflict comes with the ID. What I want is: ID Subject Date 1 tableA xx-xx-xx 2 tableB xx-xx-xx I hope this was more illustrative ![]() |
|
#4
|
|||
|
|||
|
New Column
Are you just displaying them all together in one location? If so why not use a UNION join and even add a column to determine which table it is coming from.
SELECT 'TableA' as 'source', ID, Subject, Date FROM TableA UNION ALL SELECT 'TableB', ID, Subject, Date FROM TableB SORT BY ID, source That way it takes the two tables and grabs all of the records from each and combines into one table. One thing to watch out for: + the Columns have to match in type + the columns will be called whatever is defined in the FIRST select + UNION ALL will display all records, even if they are duplicates while UNION will not |
|
#5
|
|||
|
|||
|
Great idea thanks a lot
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Unique id's |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|