Cross Join - Sql Server
-
I have two table which are TBL_A and TBL_B. TBL_A contain two record, TBL_B have no record. Select ta.Name From TBL_A ta I get two record. But If wrote following query Select ta.Name From TBL_A ta, TBL_B tb No any record get, because SQL Server defaultly use CROSS JOIN like this; Select ta.Name From TBL_A AS ta CROSS JOIN TBL_B AS tb How can I close CROSS JOIN. I want to get record when TBL_B also have no record.. Actually I use "where" statement, but if one table have no record on FROM statement so I did not get result related about CROSS JOIN.
-
I have two table which are TBL_A and TBL_B. TBL_A contain two record, TBL_B have no record. Select ta.Name From TBL_A ta I get two record. But If wrote following query Select ta.Name From TBL_A ta, TBL_B tb No any record get, because SQL Server defaultly use CROSS JOIN like this; Select ta.Name From TBL_A AS ta CROSS JOIN TBL_B AS tb How can I close CROSS JOIN. I want to get record when TBL_B also have no record.. Actually I use "where" statement, but if one table have no record on FROM statement so I did not get result related about CROSS JOIN.
If I understand your question correctly, what you are looking for is an OUTER JOIN: http://msdn.microsoft.com/en-us/library/ms187518.aspx[^]
-
I have two table which are TBL_A and TBL_B. TBL_A contain two record, TBL_B have no record. Select ta.Name From TBL_A ta I get two record. But If wrote following query Select ta.Name From TBL_A ta, TBL_B tb No any record get, because SQL Server defaultly use CROSS JOIN like this; Select ta.Name From TBL_A AS ta CROSS JOIN TBL_B AS tb How can I close CROSS JOIN. I want to get record when TBL_B also have no record.. Actually I use "where" statement, but if one table have no record on FROM statement so I did not get result related about CROSS JOIN.
Take a look at this Visual Representation of SQL Joins[^], it may help you understand what joins to use and how to use them
Never underestimate the power of human stupidity RAH
-
I have two table which are TBL_A and TBL_B. TBL_A contain two record, TBL_B have no record. Select ta.Name From TBL_A ta I get two record. But If wrote following query Select ta.Name From TBL_A ta, TBL_B tb No any record get, because SQL Server defaultly use CROSS JOIN like this; Select ta.Name From TBL_A AS ta CROSS JOIN TBL_B AS tb How can I close CROSS JOIN. I want to get record when TBL_B also have no record.. Actually I use "where" statement, but if one table have no record on FROM statement so I did not get result related about CROSS JOIN.
This may help
declare @tblA table(recordA varchar(10))
declare @tblB table(recordB varchar(10) null)
insert into @tblA select 'recA1' union all select 'recA2'Query:
select a.* from @tblA a full join @tblB b
on a.recordA = b.recordB:)
Niladri Biswas
-
I have two table which are TBL_A and TBL_B. TBL_A contain two record, TBL_B have no record. Select ta.Name From TBL_A ta I get two record. But If wrote following query Select ta.Name From TBL_A ta, TBL_B tb No any record get, because SQL Server defaultly use CROSS JOIN like this; Select ta.Name From TBL_A AS ta CROSS JOIN TBL_B AS tb How can I close CROSS JOIN. I want to get record when TBL_B also have no record.. Actually I use "where" statement, but if one table have no record on FROM statement so I did not get result related about CROSS JOIN.
Here is the syntax for two tables
INSERT INTO answers
(user_id, question_id)
(SELECT u.id AS user_id, q.id AS question_id FROM users u, questions q);To learn more about cross join in SQL check this out. Cross Join in SQL | SQL Cross Join - Scaler Topics[^]