开发者

SQL Server and Oracle joins tutorials

开发者 https://www.devze.com 2023-01-21 22:38 出处:网络
Question 1: I am learning SQL Server and Oracle joins (inner joins, outer joins...) and case statements syntax. Though I can google for the info, but would

Question 1: I am learning SQL Server and Oracle joins (inner joins, outer joins...) and case statements syntax. Though I can google for the info, but would like to ask for some sites, links, and materials that fully explain the joins and case statments.

Question 2: I am running a simple statment below which gives the output as follow:

select '''' + name + '''' + ',' as Emp_Names
from dbo.employee

Emp_Names
'Jason',
'Robert',
'Celia',
'Linda',
'David',
'James',
'Alison',
'Chris',
'Mary',

Is there a way in SQL that can show my desired output as:

Emp_Names  
'Jason', 'Robert','Celia','Linda','David','James','Alison','Chris','Mary',

i can press a Delete and End together to get there but only for a handful records but not for a hundred records..开发者_如何学Go.


You can start here.


SQL Server and Oracle joins (inner joins, outer joins...)

Good link for that.

...case statements syntax.

The CASE expression is ANSI, and supported in Oracle 9i+ and SQL Server 2000+ - it's the same on both. Oracle's PLSQL also has a CASE statement, and the difference between the two is that the PLSQL version ends with END CASE, rather than END.


In SQL Server 2005 or later, you can use the stuff function if you want all the names in one column.

SELECT STUFF(( SELECT DISTINCT TOP 100 PERCENT
                                ',' + Name
                        FROM    employee
                        ORDER BY ',' +Name
                        FOR XML PATH('')
                      ), 1, 1, '') 

or

select STUFF(( SELECT DISTINCT TOP 100 PERCENT
                                ''',''' + Name
                        FROM    employee 
                        ORDER BY ''',''' + Name
                        FOR XML PATH('')
                      ), 1, 2, '') + ''''      

Otherwise you could use the pivot command to have each name as its own column. The only thing with using the pivot command is that you need to know the names before hand or else you would use it in conjunction with the stuff function.


Joins are more of general SQL. They don't have different commands specific to SQL-Server or Oracle.

Microsoft has T-SQL and Oracle has PL/SQL.

T-SQL - use this link

0

精彩评论

暂无评论...
验证码 换一张
取 消