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 |
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2004-07-22 : 10:03:46
|
| I have two tables in the below format...Table1ProcId|LotId|TravLotId________________________1001| 1| 1011002| 1| 1021003| 1| 1031004| 1| 1041005| 2| 2101006| 2| 2201007| 2| 2401008| 3| 451009| 3| 46Table2ProcessId|ProcNum______________1001 | 51002 | 101003 | 31004 | 301005 | 5001006 | 231007 | 4001008 | 1001009 | 90How do i write a query to get the following output:LotId|TravLotId|ProcNum________________________1 | 103| 32 | 220| 233 | 46| 90I mean i want to get the lowest ProcNum with in a group of Lot id'sThanks in advance... |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-07-22 : 10:06:23
|
| ???? Didn't I already answer this question? Is this a homework question?MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2004-07-22 : 10:28:03
|
| Nope...I came across this kind of a table structure and was wondering how do i get the desrired result...I tried something like this:SELECT t1.LotID, t1.TravLotID,t2.ProcNumFROM table1 t1INNER JOIN table2 t2ONt2.ProcessId = t1.ProcIdWHERE t2.ProcNum In (select top 1 t2.ProcNum from dbo.Process where t2.ProcessId = t1.ProcId ORDER BY t2.ProcNum Asc);But didnt work.... |
 |
|
|
JasonGoff
Posting Yak Master
158 Posts |
Posted - 2004-07-22 : 10:35:09
|
| [code]SELECT A.LotID, A.TravLotId,MIN(B.ProcNum)FROM Table1 A INNER JOIN Table2 B ON A.ProcID=B.ProcessIDGROUP BY LotID, TravLotID[/code] |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-07-22 : 10:45:17
|
| Well, that's funny because someone asked this EXACT same question earler on another thread.http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=37769Isn't that just the oddest of all coincidences that two people would ask the EXACT SAME questions and it's not related to homework????MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
JasonGoff
Posting Yak Master
158 Posts |
Posted - 2004-07-22 : 10:51:04
|
LOL, and having read that thread, and seen all the info missed from the original question above, my solution won't work !Definitely homework |
 |
|
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2004-07-22 : 11:06:28
|
| Derrick,I came across this kind of post on some other forum and was trying to write a SQL query ( i am trying to learn)...Thanks for the solution.. |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-07-22 : 11:36:26
|
| You need to spell that out in your posts. :) I don't mind spending time on here helping people. I don't want to help people cheat on homework assignments though. I hope you understand that.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|
|
|