473,609 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help to structure query without using subselects

Hi List

Can anyone help me to do the following without the need of subselects:
I have a table that contains rows where mostly, the only common field is
the "name". The rest of the data fields, even though they are related to
the "name", differs from row to row ( they are things like the address
etc, which could have changed on the next entry for the same "name")

What I'm trying to get out of the table is a list of all the names (
with the duplicates pruned out by DISTINCT) and other collumns for the
row with the highest id.

This works:

select distinct name, max(id) as mid from table group by name

but it only returns the name and the highest id for such a name.

if I try this:

select distinct name, max(id) as mid, anything_else from table group by
name

it returns the FIRST "anything_else" , and not the value in the last row
for that name ( as I would like it to)

Any help?

mysql, query

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
0 1418

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
517
by: Petre Agenbag | last post by:
Hi List Can anyone help me to do the following without the need of subselects: I have a table that contains rows where mostly, the only common field is the "name". The rest of the data fields, even though they are related to the "name", differs from row to row ( they are things like the address etc, which could have changed on the next entry for the same "name")
5
1941
by: Got2Go | last post by:
Hello Group, I have a table that has 3 columns: ID (int), datetime, Value(varchar) ID = ID for the SNMP device datetime = time record was added value = value added for that device. This table contains sample # values taken from a device (SNMP) every 5
12
6971
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully unambigous tree structure. The root node can have whatever value you prefer, I suppose NULL would be good for a start. What I want to do is finding the way from an arbitrary node in the tree. Example:
7
12062
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound to know this number after the first FETCH, isn't it? On a side note, why queries using LIMIT are SO terribly slow, compared to cursors and sometimes even ones without LIMIT? Shouldn't LIMIT be internally implemented using cursor mechanism then?...
3
6410
by: Kumar | last post by:
Hi Need a help in rewritting the folwoing SQL which is taking more than a day to give resultset. Is there anything wrong in this SQL coding ? SELECT DISTINCT 214 AS BATCH_ID, TAB1.customer_sk, TAB1.CUSTOMER_ID, TAB1.product_line_sk, COUNT(DISTINCT TAB1.ACCOUNT_SK) AS COUNT
5
1677
by: Bob Stearns | last post by:
When I run the following query with the two sections commented out, the response time is between 1 an 2 seconds; with the first indicated section enabled, the response goes up to 15 seconds even though t1.bh_disposal_code IS NOT NULL in only one row; with the second section enabled, it goes up to 592 seconds, even though t1.mating is NULL in all the rows chosen. Why should the (supposedly never executed) scalar subqueries cost so much? It...
6
2422
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs. the table structure is the following Job TypeID
0
977
by: Tarun Mistry | last post by:
Hi guys, I have posted this in 2 groups hoping to catch up on some difference knowledge. I am making an application in c# with a SQL 2000 back end. I am trying to use the new dataset available in VS 2005 to auto-magically provide my data access layer. Unfortunately, in order to take advantage of this automation, I cannot use JOINs in my queries, I must use subselects, however i'm worried about the performance hit subselects may have.
0
5557
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
1595
by: claudia.inaciofong | last post by:
Hi, I have this query below: select groupname from detentgroups where groupid = (select notedDestGroupID from DetentRequestedDest where groupid =1 and detentnumber =1) the groupid and detentnumber would be a variable...
0
8145
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8556
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8410
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2541
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1690
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.