Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 joining colums in select

Author  Topic 

vinay789
Starting Member

40 Posts

Posted - 2009-05-06 : 07:43:16

Hi to everyone
i am a newbie to mssql my problem is in my db i have 2 queries like this
select t1,t2,t3 from T1 and another query select s1,s2,s3 from S1 now i want to add s1 field to T1 any suggestions pls

Edit/Delete Message

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-06 : 07:45:12
you are not clear. post sample data, table structure and output you need.
Go to Top of Page

vinay789
Starting Member

40 Posts

Posted - 2009-05-06 : 08:04:15
i want to join field s1 with T1 i used JOIN like this
select t1,t2,t3,s1 from T1 JOIN S1 ON (T1.adid=S1.adid)
but this code is not giving correct output in my JSP page any help
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-06 : 08:28:25
again,, "post sample data, table structure and output you need"
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-05-06 : 08:36:49
Are you meaning that you want to join two tables together or two columns if it's the latter use the "+" to join them togther, otherwise it looks like you already able to join the tables from your post above

like

select T1ColumnName+s1ColumnName from T1 INNER JOIN S1 ON T1.adid=S1.adid
Go to Top of Page

vinay789
Starting Member

40 Posts

Posted - 2009-05-06 : 08:40:34
ok in my db i have two tables one is employee and other is staff
For table employee eid,ename,esal are the field names
For staff sno,sname,ssal are the field names
Now i want to combine the field name {sno} with employee table give me a select statement how to
combine the both tables
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-06 : 09:05:50
It is an awesome challenge to give sample data, table structure and needed output - isn't it?



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-06 : 09:12:36
[code]select eid,ename,esal from employee
union all
select sno, sname, ssal from staff[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vinay789
Starting Member

40 Posts

Posted - 2009-05-06 : 09:22:40
Hi
khtan thanx for ur response i want to add only sno to employee not all the fields
Go to Top of Page

vinay789
Starting Member

40 Posts

Posted - 2009-05-06 : 09:24:00
quote:
Originally posted by khtan

select eid,ename,esal from employee
union all
select sno, sname, ssal from staff



KH
[spoiler]Time is always against us[/spoiler]







Hi
khtan thanx for ur response i want to add only sno to employee not all the fields
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-06 : 09:26:21
then can you kindly provide us the table DDL, sample data and HOW DO YOU WANT THE RESULT TO LOOKS LIKE.

cause . . . all of us are just guessing . . nobody knows what you want


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vinay789
Starting Member

40 Posts

Posted - 2009-05-06 : 09:34:19
quote:
Originally posted by khtan

then can you kindly provide us the table DDL, sample data and HOW DO YOU WANT THE RESULT TO LOOKS LIKE.

cause . . . all of us are just guessing . . nobody knows what you want


KH
[spoiler]Time is always against us[/spoiler]




i used JOIN in select statement like this
select eid,ename,esal,sno from employee JOIN staff ON employee.username=staff.username
but this code is not working properly pls modify
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-05-06 : 09:38:34
Even after so many of us asking for sample data and expected output...y do you hesitate to provide them? We do not have access to your data.

Please provide sample data and expected output to provide a working solution for you.
Go to Top of Page

vinay789
Starting Member

40 Posts

Posted - 2009-05-06 : 10:11:45
I need to pull data from 2 or more sources (tables or views) and combined them into 1 logical unit. This is my code i used JOIN in select statement like this
select eid,ename,esal,sno from employee JOIN staff ON employee.username=staff.username
but this code is not working properly pls modify
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-05-06 : 11:14:34
Try following the first link in my signature, then restate your question with all of the DML and DDL that has been requested.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

mailsomani
Starting Member

4 Posts

Posted - 2009-05-07 : 08:50:22
Hi,
If you provide some sample data and how you want optput then somebody can help you.Try to create some sample data and give the output how you want, based on that possibly we can provide query for that.

Reagrds
Pawan Somani
WINWIRE TECHNOLOGIES


Pawansomani
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-07 : 09:09:26
quote:
Originally posted by vinay789

ok in my db i have two tables one is employee and other is staff
For table employee eid,ename,esal are the field names
For staff sno,sname,ssal are the field names
Now i want to combine the field name {sno} with employee table give me a select statement how to
combine the both tables




Do you mean this?

select sno+'-'+eid as eid,ename,esal from employee JOIN staff ON employee.username=staff.username


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -