tags:

views:

25

answers:

1

Hi guys,

I want to compare a table coloum with the last entry of another (by foregn key given) table. And then fobit the entry, when it's the last.

So:

  • Table 1 - Coloum userid - value: 1000
  • Table 2 . Coloum userID - value: 1000 // Coloum rowID: 1
  • Table 2 . Coloum userID - value: 2000 // Coloum rowID: 2
  • Table 2 . Coloum userID - value: 1000 // Coloum rowID: 3

Should be: NO

So:

  • Table 1 - Coloum userid - value: 1000
  • Table 2 . Coloum userID - value: 1000 // Coloum rowID: 1
  • Table 2 . Coloum userID - value: 2000 // Coloum rowID: 2

Should be: YES

My try:

(from a in dc.table1
where a.UserID != a.table2.Last().UserID)

But it don't work. Error is "The query operator 'Last' is not supported."

+1  A: 

Last on a database query doesn't make sense unless you also have an order by:

a.table2.OrderBy(x => x.id).Last()

It might also perform better if you order by descending and use First instead, although I haven't tested it.

Mark Byers
Why doesn't Last make sense without an OrderBy? There's always a default ordering of the items/rows...
Mark Seemann
Because the database is free to change the ordering on disk for performance reasons. It won't crash or anything like that, but which row you get is undefined. It might work as you expect until you hit 10000 rows, then suddenly stop working when the database decides to reorder the data.
Mark Byers
Same Problem: "The query operator 'Last' is not supported"
Kovu
Descendening and First () function!
Kovu