asked on
ASKER
SELECT
ifnull(ot.ordername, NAMES.ordername) AS ordernames
, ifnull(ot.tid, tids.tid) AS tids
, ifnull(ot.quantity, 0) AS quantity
, ot.location
FROM (
SELECT DISTINCT ordername
FROM ordertable
) NAMES
CROSS JOIN ( /*<< use "CROSS JOIN" it clearly identifies */
SELECT DISTINCT tid /*<< that the Cartesian product is deliberate */
FROM ordertable
) tids
LEFT JOIN ordertable ot ON (
ot.ordername = NAMES.ordername
AND ot.tid = tids.tid
)
ORDER BY
ordernames /* << optional, can use the selection list aliases here */
, tids /* << optional, can use the selection list aliases here */
;
While an inner join (without ON conditions) appears to work, it also appears "very odd" and might be missing ON conditions, for maintenance purposes using CROSS JOIN makes it clear that no ON conditions are required. http://sqlfiddle.com/#!2/64da5/1
ASKER
ASKER
Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.
TRUSTED BY