SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 02-02-2008, 03:10 PM
RayForster RayForster is offline
Junior Member
 
Join Date: Feb 2008
Posts: 1
RayForster is on a distinguished road
Default ANY dialect question:

Select Query with different fields


Hello All...

I'm sure this is very simple to those who know... but I'm trying to do what I think should be a simple query, but I'm struggling to get exactly what I want...

Suppose I have a table similar to the below:

Table:
email - firstname - lastname
mrx@mycompany.com - Fred - Bloggs
mrx@mycompany.com - F - Bloggs
mrx@mycompany.com - Fred - Blogs
me@here.com - Pam - Smith
me@here.com - Pamela - Smith
you@there.com - Tom - Thumb

All I want to do is return / query that returns one value for each entry as follows:
mrx@mycompany.com - Fred - Bloggs
me@here.com - Pam - Smith
you@there.com - Tom - Thumb

I've used the DISTINCT keywork, but because the other fields are unique, all rows are returned still....

Similarly, If I wanted to query all records in the table that have multiple records for an email address in the table above, how would I do that?

Many thanks in advance....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 02-05-2008, 10:17 PM
Dimitar
 
Posts: n/a
Default ANY answer. Re: Select Query with different fields

Hi,

Does this solve the issue:
Code:
SELECT email, max(firstname),max(lastname) FROM t GROUP BY 
email;
If yes, you could consult your SQL manual about grouping and grouping functions that filter results within each group.

Hope this helps,
Dimitar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:23 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8