I have 2 tables like which I would like to query to form a new table.
table 1
number type serial index 1000001 613 3 1 1000001 613 3 1 1000001 613 3 1 1000001 613 3 1 1000001 613 4 1 1000001 613 3 1
table 2
number type serial index 1000001 613 3 2 1000001 613 3 3 1000001 613 3 4 1000001 613 3 4 1000001 613 4 2 1000001 613 3 1
I am looking for a query which gives a resultant of indexes and numbers like this, and adds the index, and gives the result:
output table number index 1000001 3 1000001 4 1000001 5 1000001 5 1000001 3 1000001 2
I want to prevent cross joins here. I can’t use where clause because the numbers are same in both tables only the index varies. How can I execute this one-to-one and not one-to-many.
I don’t think it’s possible to do what you are asking. You would have to be able to distinguish each row uniquely to guarantee a 1-to-1 result (this is normally the job of your index column or ID column).
You might be able to jerry-rig something with rownum, however, if the tables are identically ordered, then perhaps you’ve over-normalised. Table 1 and 2 should really just be one, and you have two index columns (index1 and index2) in the one table.