473,473 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Selecting unique values:K@N@!:

I have two tables as below:

CREATE TABLE domain_types (
type_id INT(4) NOT NULL AUTO_INCREMENT,
name VARCHAR(10) UNIQUE NOT NULL,
description VARCHAR(75),
PRIMARY KEY(type_id)
) TYPE=INNODB COMMENT="Types of domains we store";

CREATE TABLE domains (
domain_id INT(6) NOT NULL AUTO_INCREMENT,
domain VARCHAR(50) UNIQUE NOT NULL,
type_id INT(4) NOT NULL,
PRIMARY KEY(domain_id)
) TYPE=INNODB COMMENT="Domains";

I can get the below result easily:

mysql> select distinct t.name,d.domain from domain_types t, domains d
WHERE t.type_id=d.type_id ORDER BY t.type_id;
+----------+------------+
| name | domain |
+----------+------------+
| hostdom1 | abc123.com |
| hostdom1 | abc124.com |
| hostdom1 | abc125.com |
| hostdom2 | abc127.com |
| hostdom2 | abc126.com |
| hostdom3 | abc128.com |
| hostdom4 | abc129.com |
| hostdom4 | abc130.com |
+----------+------------+
8 rows in set (0.01 sec)

But what I really need is a result like

+----------+------------+
| name | domain |
+----------+------------+
| hostdom1 | abc123.com |
| hostdom2 | abc127.com |
| hostdom3 | abc128.com |
| hostdom4 | abc129.com |
+----------+------------+

where only the t.name and d.domain pair with the highest
domain_id for each type_id are given. Is there a way to do this without
resulting to seperate SQL queries for each entry in the domain_types
table? I'm using MySQL 4.0.14 on FreeBSD 5.1.

Alec

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my******************@paypal.com

--
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 1197

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

Similar topics

0
by: Alec Smith | last post by:
I have two tables as below: CREATE TABLE domain_types ( type_id INT(4) NOT NULL AUTO_INCREMENT, name VARCHAR(10) UNIQUE NOT NULL, description VARCHAR(75), PRIMARY KEY(type_id) ) TYPE=INNODB...
0
by: Alec Smith | last post by:
I have two tables as below: CREATE TABLE domain_types ( type_id INT(4) NOT NULL AUTO_INCREMENT, name VARCHAR(10) UNIQUE NOT NULL, description VARCHAR(75), PRIMARY KEY(type_id) ) TYPE=INNODB...
8
by: nescio | last post by:
hello, i have an array and i don't know the content of it, but i want only unique values. in php there is a function to do this, but how must i do this in javascript? i have tried a lot and...
11
by: sqlservernewbie | last post by:
Hi Everyone, Here is a theoretical, and definition question for you. In databases, we have: Relation a table with columns and rows
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.