I have the following SQL query:
SELECT
kvknum.cd_hfdrelnr,
kvknum.cd_kvkanum,
relName.cd_hfdrelnr
FROM
(
SELECT
cd_hfdrelnr,
cd_kvkanum
FROM er_105
WHERE cd_kvkanum IN
(
SELECT cd_kvkanum
FROM er_105
GROUP BY cd_kvkanum
HAVING COUNT(*) > 1
)
AND cd_kvkanum != ''
ORDER BY cd_kvkanum
) AS kvknum
LEFT OUTER JOIN
(
SELECT
cd_hfdrelnr,
cd_relnaam
FROM er_101
) AS relName
ON kvknum.cd_hfdrelnr = relName.cd_hfdrelnr
The GROUP BY function is not allowed and it is needed so the same cd_kvkanum values are shown together under each other, is there a work around for this or how is this possible to achieve?
Following error comes with it:
"Msg 1033, Level 15, State 1, Line 21 The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified. Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword 'AS'."
when I run the following query:
SELECT
cd_hfdrelnr,
cd_kvkanum
FROM er_105
WHERE cd_kvkanum IN
(
SELECT cd_kvkanum
FROM er_105
GROUP BY cd_kvkanum
HAVING COUNT(*) > 1
)
AND cd_kvkanum != ''
ORDER BY cd_kvkanum
(First subquery of the join) the results look like:
1235 - 123
4652 - 123
8569 - 1234
4985 - 1234
Though I want to add cd_relnaam to the result list, when Just use an JOIN on the query my results are blank...
anybody knows what I do wrong?