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.
| Author |
Topic |
|
edpfister
Starting Member
5 Posts |
Posted - 2009-07-31 : 19:47:34
|
| Here is a shorthand of the tables I am working with and some sample data.Table = InfoSerial Run111 1111 2111 3111 4222 1222 2333 1333 2Table = PMTSSerial Run Build111 1 B111 2 B222 1 A333 1 BSo what I am trying to do is make a query that will give me all rows in the Info table that are from a particular build (user input). So if I request Build B I would want.Serial Run111 1111 2111 3111 4333 1333 2The query I am using is:SELECT * FROM Info INNER JOIN PMTS ON Info.Serial = PMTS.Serial WHERE PMTS.Build = <user input>This gives me the records I want but I get duplicate entries. I thought about using DISTINCT but one of the columns is text which causes problems.Am I going about this in the wrong way? What do you suggest, thank you. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-07-31 : 21:07:44
|
| [code]SELECT *FROM InfoINNER JOIN PMTSON Info.Serial = PMTS.SerialAnd Info.Run = PMTS.runWHERE PMTS.Build = <user input>[/code] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-08-01 : 11:41:22
|
quote: Originally posted by russell
SELECT *FROM InfoINNER JOIN PMTSON Info.Serial = PMTS.SerialAnd Info.Run = PMTS.runWHERE PMTS.Build = <user input>
Using column RUN in joining would not give the wanted output posted by edpfister. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-08-01 : 16:06:52
|
[code]Declare @UserInput char(1)set @UserInput = 'B'SELECT a.*FROM Info aINNER JOIN (Select distinct aa.Serial from PMTS aa where aa.Build = @UserInput) bON a.Serial = b.Serial Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-08-01 : 16:47:19
|
[code]SELECT i.Serial, i.RunFROM Info AS iWHERE EXISTS (SELECT x.Serial FROM PMTS as x WHERE x.Serial = i.Serial AND x.Build = 'B')[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
|
edpfister
Starting Member
5 Posts |
Posted - 2009-08-03 : 13:44:59
|
| This is what I needed. Thank you. |
 |
|
|
|
|
|