hi,
i was wondering which type of join should i use to get an empty result set when there is no record in one of the tables
i.e : i have two tables : Element and Attribute
the table Element has elements in it...
then there is the attributes table, each attribute is related to an element _but_ not every element has attributes
so now i want to know if element with name : "element3" has an attribute.
for that i do a join:
is that INNER JOIN going to return an empty resultset?
ah I think found the answer i just have to specify the column i want to get
as there is no attribute it should return empty set, right?
edit post:
sorry, now i rethink my problem and what i really want is to be able to differentiate 3 cases in one single query:
1. there is no such element
2. there is such element but it has no attribute
3. there is such element and has an attribute
so my query should return for each case:
1. empty set
2. row with element but without attribute
3. row with element and attribute
would this query make the trick?
i was wondering which type of join should i use to get an empty result set when there is no record in one of the tables
i.e : i have two tables : Element and Attribute
the table Element has elements in it...
Code:
[B]Element[/B] id | name ---|--------------- 0 | element0 1 | element1 2 | element2 3 | element3 4 | element4
Code:
[B]Element[/B] elementId | attribute ----------|----- 2 | attributeForElement2 4 | attributeForElement4
for that i do a join:
Code:
SELECT *
FROM Element AS e
[B]INNER[/B] JOIN Attribute AS a
WHERE e.name = 'element3'
ah I think found the answer i just have to specify the column i want to get
Code:
SELECT a.attribute
FROM Element AS e
[B]INNER[/B] JOIN Attribute AS a
WHERE e.name = 'element3'
edit post:
sorry, now i rethink my problem and what i really want is to be able to differentiate 3 cases in one single query:
1. there is no such element
2. there is such element but it has no attribute
3. there is such element and has an attribute
so my query should return for each case:
1. empty set
2. row with element but without attribute
3. row with element and attribute
Code:
SELECT a.attribute, e.element
FROM Element AS e
[B]INNER[/B] JOIN Attribute AS a
ON (e.id = a.elementId)
WHERE e.name = 'element3'
Comment