Hope this helps
Main Topics
Browse All TopicsI have a query .This is selecting records from 6 table and displaying.
I want only the FIRST record returning a15.title title to appear in the list, however when there are different entries in a14.processed processed, it returns a duplicate entry.
I have attempted to use group by a15.title but it returns no records whenever I put in a group by parameter.
If the record is coming from a single table then i know how to use row_number() over (partition).
But from many tables i not able to do it.
Any help appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
@rrjegan17:i am getting this error..
Msg 1033, Level 15, State 1, Line 4
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
@Mortaza_doulaty:I am using this in a php script so i cant create a view...
Did you not see the solution provided by ralmada http:#a25106497 ? It does not have the syntax error with the ORDER BY clause in the derived table.
Thank you AC.
@jack,
basically the problem with rrjegan solution is that it has an order by in the subquery.
select * from (
select .... from
where .....
order by ... -- THIS IS WRONG.
) a
The above is incorrect. you need to move the order by clause outside of the subquery.
select * from (
select .... from
where .....
) a
order by ... -- THIS IS CORRECT
that's what I've suggested in my previous comment 25106497.
@ralmada : oops sorry ur query i working ...When i have changed the values.But see it gets wrong records...
title1 author1 1234 2009-01-08 00:00:00.000 f this is a movie 1
title1 author1 4321 2009-01-08 00:00:00.000 f this is a movie 1
title3 author3 8765 2009-01-08 00:00:00.000 song this is a song 1
title2 author2 5678 2009-02-08 00:00:00.000 f this is a movie 1
Ok i will check ur solution.
1.One quick question, Is it wrong to use the order by clause in the sub query?
>>>row_number() over (partition by a15.title order by a12.creation_date)
2.Also here we should use a orderby clause?
3.Also partition by means like group by?
4.why not we use rank() function here ,how it is different from the row_number().
Thanks for all ur time.
U can also the results here...
the working code displays duplicates, which is what I'm trying to fix...
http://www.myrcpl.com/onor
This is the php code...
http://www.myrcpl.com/onor
Business Accounts
Answer for Membership
by: Mortaza_doulatyPosted on 2009-08-15 at 05:01:54ID: 25105081
Try to re-write your query as a single view, then try to use ROW_NUMBER() on a view.