max

How to get all the fields of a row using the SQL MAX function?

Consider this table (from http://www.tizag.com/mysqlTutorial/mysqlmax.php): Id name type price 123451 Park's Great Hits Music 19.99 123452 Silly Puddy Toy 3.99 123453 Playstation Toy 89.95 123454 Men's T-Shirt Clothing 32.50 123455 Blouse Clothing 34.97 123456 Elec...

SQL Max Group By Query Help

Hi All, I have a quick question. How do I select the two values I need in one query? Currently I'm doing this, which works fine, but it's obviously running two queries when one should do the trick. I tried MAX(columnA) and GROUP BY ColumnB, but that returns multiple row. I only want one row returned. DECLARE @biID bigint , @dtThresho...

Help Converting T-SQL Query to LINQ Query

I am new to LINQ, and so am struggle over some queries that I'm sure are pretty simple. In any case, I have been hiting my head against this for a while, but I'm stumped. Can anyone here help me convert this T-SQL query into a LINQ query? Once I see how it is done, I'm sure I'll have some question about the syntax: SELECT BlogTitle FRO...

NHibernate: SELECT MAX() with JOIN

I have a Vendor. Every Vendor has several Reservations, with a ReservationDate on it. I want a list of Vendors that have not made a reservation yet today. In SQL I would do something like this: SELECT v.Id, MAX(r.ReservationDate) AS MaxDate FROM Vendor v INNER JOIN DailyReservation r ON v.Id = r.Vendor_Id GROUP BY v.Id HAVING MAX(r....

how to create a linq query using join and max

I have 2 tables in my linq dbml. One is people with a uniqueid called peopleid and the other is a vertical with a foreign key for peopleid and a uniqueid called id. I need to create a type of linq query that does a left outer join on people and gets the latest record in the vertical table based off the max(id) column. Can anyone sugge...

MySQL query problem on group by and max

My table structure is (id,cluster,qid,priority). I'm trying to figure out how I can display the maximum value of priority for each cluster. Say cluster 1 has priorities 100, 102, 105. I want to display the record containing 105. Please help. ...

How to get MAX value of a version-number (varchar) column in T-SQL

I have a table defined like this: Column: Version Message Type: varchar(20) varchar(100) ---------------------------------- Row 1: 2.2.6 Message 1 Row 2: 2.2.7 Message 2 Row 3: 2.2.12 Message 3 Row 4: 2.3.9 Message 4 Row 5: 2.3.15 Message 5 I want to write a T-Sql query that will get ...

Problem in finding next / previous row in mysql

SELECT id ,MAX(status) AS status FROM Mail WHERE status < (SELECT status FROM Mail WHERE id = 1000) GROUP BY status ORDER BY status DESC LIMIT 1; I am using this query to find the previous row of the current row 1000.Here i am getting NULL values if i use the status column which is not unique.where as it gives proper values...

MAX() and MAX() OVER PARTITION BY produces error 3504 in Teradata Query

I am trying to produce a results table with the last completed course date for each course code, as well as the last completed course code overall for each employee. Below is my query: SELECT employee_number, MAX(course_completion_date) OVER (PARTITION BY course_code) AS max_course_date, MAX(course_completion_d...

Simple MySQL question - MAX(field) ?

Hi just a simple question I know how to get the most recurring field from a table SELECT MAX(field) FROM table But how do I get the Second most recurring field from a table? Thank you. ...

how do you get "real" sql distinct with hibernate criteria queries?

I have a Hibernate criteria query that is incorrectly pulling out max results. In many cases, when I specify 20 max results, the query actually only returns 1 or 5 results, because the restrictions return many duplicates. Criteria c = session.createCriteria(DomainObject.class); c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); c.cr...

Max value in a many-to-many relationship

I'm using SQL Server 2008 and I have 3 tables, x, y and z. y exists to create a many-to-many relationship between x and z. x y z -- -- -- id xid id zid sort All of the above fields are int. I want to find the best-performing method (excluding denormalising) of finding the z with the highest sort for ...

SQL how to count all rows up to a max value

I am having trouble counting the number of rows until it reaches a certain PK. My PK is called id and I want to count all rows until i reach a specified id I have tried using this query but it doesn't work probably becuase I am using a MySQL table select max(count(*)) from news where id=18 group by id I get this error Invalid us...

SQL using count value as offset

This is a follow on from another question i made I have this query that counts all the records up to a certain point i choose whcih works fine SELECT count(*)FROM news WHERE id < 18 this query gives me a count of 7 I am now having problems with the offset which would be the result of the above query I tried using this query SELECT...

iPhone Documents directory maximun size

Hi! I'm just wondering due to new personal project which is the limit (in MB or GB) of documents directory of my app. I just wanna save a lot of photos, so, has documents directory a limit for archiving downloaded photos? Will Saving 300MB of photos produce slow downs on 3G? If there is no limit, I think that limit shoud be the 8 16 32...

SQL - aggregate function to get value from same row as MAX()

I have one table with columns channel, value and timestamp, and another table with 7 other columns with various data. I'm joining these two together, and I want to select the maximum value of the value column within an hour, and the timestamp of the corresponding row. This is what I've tried, but it (obviously) doesn't work. SELECT ...

TSQL Select Max

Userid FirstName LastName UserUpdate 1 Dan Kramer 1/1/2005 1 Dan Kramer 1/1/2007 1 Dan Kramer 1/1/2009 2 Pamella Slattery 1/1/2005 2 Pam Slattery 1/1/2006 2 Pam Slattery 1/1/2008 3 ...

MOSS 2007 - Maximum number of views for one list?

Is there a maximum number of views you can create for a list in SharePoint? I mean views like the ones which are listed in the top right corner o the AllItems.aspx page: Are there performance issues which arise when you add a lot of views to one list, like 50-100? ...

SQL Server: Select Max Limit 1 from Group

Using SQL Server. Ok, I'm making an in webpage cache system. I wanted to make a simple page rank system along with output. The problem is, I want to display the recordset with the highest relevance score per unique domain. One domain may have multiple records but with different titles, descriptions, etc. he probem is,instead of getting 1...

How can I select several rows with the Max column value which is grouped by another column?

I want to get the movie, character_name, and Visits of the 4 rows(*) having the max "Visits" value group by movie. My table (D) is like this: movie character_name Visits 1 Owen Lars 1 1 Obi-Wan Kanobi 2 1 Luke Skywalker 3* 2 Princess Leia 2 2 Luke Skywalker 3* 2 R2-D2 3* 3 Jabba t...