Reputation: 842
i have 1 long table and 1 short table:
the long table looks like this:
LongTable:
+--------------+----------+----------+----------+
| Kabelnummer | GL |more data |even more |
+--------------+----------+----------+----------+
| 1 | 850 | x | x |
+--------------+----------+----------+----------+
| 2 | 850 | x | x |
+--------------+----------+----------+----------+
| 3 | 1300 | x | x |
+--------------+----------+----------+----------+
| 4 | 1300 | x | x |
+--------------+----------+----------+----------+
and
ShortTable:
+--------------+----------+----------+----------+
| data | GL |more data |numericVal|
+--------------+----------+----------+----------+
| x | 850 | x | 0.2345 |
+--------------+----------+----------+----------+
| x | 1300 | x | 0.2849 |
+--------------+----------+----------+----------+
I would like a query that copies the column "numericVal" into the table "LongTable" where GL.Longtable is the same as GL.shorttable:
LongTable:
+--------------+----------+----------+----------+----------+
| Kabelnummer | GL |more data |even more |numericVal|
+--------------+----------+----------+----------+----------+
| 1 | 850 | x | x | 0.2345 |
+--------------+----------+----------+----------+----------+
| 2 | 850 | x | x | 0.2345 |
+--------------+----------+----------+----------+----------+
| 3 | 1300 | x | x | 0.2849 |
+--------------+----------+----------+----------+----------+
| 4 | 1300 | x | x | 0.2849 |
+--------------+----------+----------+----------+----------+
How do I do this?
Upvotes: 0
Views: 61
Reputation: 1939
SELECT lt.Kabelnummer, lt.GL, lt.X, lt.Y, st.numericVal
FROM LongTable lt
INNER JOIN ShortTable st ON lt.GL = st.GL
You use a JOIN
to accomplish this.
You can read about joins here:
Upvotes: 1
Reputation: 32602
Try to join both tables with INNER JOIN
:
SELECT L.*, s.numericVal
FROM LongTable l
JOIN sortTable s
ON l.GL = s.GL
Upvotes: 1