sql joins
-
- Posts: 639
- Joined: Sun Apr 10, 2011 9:53 pm
Re: sql joins
You don't know anything about joins?
-
- Posts: 639
- Joined: Sun Apr 10, 2011 9:53 pm
Re: sql joins
I'm brain dead after today.....
Inner joins = only those that match
Outer = all and nulls for the non match
left = everything from the first table in the join and matches/null
full outer = non matching
.........ugh my brain hurts to much at the moment to explain what I need... .. 1 sec
I want to combine both tables primary keys into one distinct list
Distinct_Primary_Key_All (from table 1 & 2), Table_1_variable, Table_2_variable
I think I just worked myself retarded... it seems simple since i typed it out.... i suck at sql.
I'm a lefty cause I always had one table with all the primary keys.
Inner joins = only those that match
Outer = all and nulls for the non match
left = everything from the first table in the join and matches/null
full outer = non matching
.........ugh my brain hurts to much at the moment to explain what I need... .. 1 sec
I want to combine both tables primary keys into one distinct list
Distinct_Primary_Key_All (from table 1 & 2), Table_1_variable, Table_2_variable
I think I just worked myself retarded... it seems simple since i typed it out.... i suck at sql.
I'm a lefty cause I always had one table with all the primary keys.
Me gusta Capitalismo Anarquista!
Re: sql joins
select id from a
union
select id from b
would give the ids. if you add the extra column from each table, I believe they are distinct based on the combination of id and other colunm. That might not be what you want.
union
select id from b
would give the ids. if you add the extra column from each table, I believe they are distinct based on the combination of id and other colunm. That might not be what you want.
Re: sql joins
ahahahaDr Exile wrote:Why don't you guys just use Fortran and simplify your live's?
I took a class in that. Taught by mathematician that solved some 100+ year old math problem.
Re: sql joins
SELECT a.id, a.f1, b.f1
FROM a
RIGHT OUTER JOIN b
ON a.id=b.id
Only if the ID exists in both tables
Guess the last case will require a program to build a table that uses just a union, reads the result and merges the fields by id.
FROM a
RIGHT OUTER JOIN b
ON a.id=b.id
Only if the ID exists in both tables
Code: Select all
mysql> select * from a;
+------+------+
| id | f1 |
+------+------+
| 1 | a |
| 2 | aa |
+------+------+
mysql> select * from b;
+------+------+
| id | f1 |
+------+------+
| 1 | b |
| 2 | bb |
+------+------+
+------+------+------+
| id | f1 | f1 |
+------+------+------+
| 1 | a | b |
| 2 | aa | bb |
+------+------+------+
Add an id only to b
+------+------+
| id | f1 |
+------+------+
| 1 | b |
| 2 | bb |
| 3 | c |
+------+------+
and this happens
+------+------+------+
| id | f1 | f1 |
+------+------+------+
| 1 | a | b |
| 2 | aa | bb |
| NULL | NULL | c |
+------+------+------+