So I have a tables that look something like this:
Communication: (Calls made)
Timestamp FromIDNumber ToIDNumber GeneralLocation
2012-03-02 09:02:30 878 674 Grasslands
2012-03-02 11:30:01 456 213 Tundra
2012-03-02 07:02:12 789 654 Mountains
2012-03-02 08:06:08 458 789 Tundra
And I want to create a new table that has all the distinct FromIDNumber and ToIDNumber's.
This is the SQL Fiddle for it.
This works:
INSERT INTO CommIDTemp (`ID`)
SELECT DISTINCT Communication.FromIDNumber
FROM Communication
UNION DISTINCT
SELECT DISTINCT Communication.ToIDNumber
FROM Communication;
and I got:
ID
878
456
789
674
213
654
365
But I wonder if there is more efficient way, because the dataset that I have has millions and millions of lines and I didn't know about the performance of UNION DISTINCT.
I originally tried something like
INSERT INTO CommIDTemp (`ID`)
SELECT DISTINCT Communication.FromIDNumber
AND Communication.ToIDNumber
FROM Communication;
but that didn't work... is there any other way to do this more efficiently? I'm pretty new to SQL, so any help would be greatly appreciated, thank you!!
A and Bwill try to insert the logicalANDresult of two strings.select 'a' and 'b'-> result =0.