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 |
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2004-06-11 : 16:15:19
|
| Table 1 emp_id123512461231Table 2emp_id address contact entry_time contacted 1235 werwer 56767 2003-02-14 10:29:00 Y1235 yuiio 66767 2003-02-16 10:40:00 N1235 vbnghf 89089 2003-02-16 10:40:00 Y1246 qeqwre 76543 2003-02-19 10:29:00 Y1246 vbnbvn 78902 2003-02-19 10:49:00 Y1239 qwewer 56767 2003-02-14 10:29:00 Y1231 jkllkj 56767 2003-02-14 10:29:00 Y1242 qweert 56767 2003-02-14 10:29:00 YI have table 1 with the list of emp_id and table 2 with emp_id details records.NowI want to retrieve the records from table 2 which has a match in table 1 and this conditions should be satisfied as well1.Now I have certain emp_id repeated.2.I want only the latest emp_id record with the latest entry time with contacted 'Y' |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-06-11 : 16:20:55
|
| To get the matches between table1 and table2, use a JOIN. To get the latest emp_id record, use MAX(entry_time) with a GROUP BY and a WHERE clause for contacted 'Y'.Tara |
 |
|
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2004-06-11 : 17:18:16
|
| When I use group by the max(entry_time) iam getting this error.Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-06-11 : 17:20:45
|
| What is your query?It would be easier if you posted your question with DDL and DML. DDL is CREATE TABLE statements for all tables, DML would INSERT INTO statements for your sample data. Then we would need to know what the expected result set would be using the sample data. We can quickly answer your questions when posted in this format as we can copy the information into Query Analyzer on our machines and test it out.Tara |
 |
|
|
|
|
|