Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 144519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:15:58+00:00 2026-05-11T08:15:58+00:00

I have a simple table with just name and email called name_email. I am

  • 0

I have a simple table with just name and email called name_email.

I am trying to fetch data out of it so that: If two rows have the same name, but one has an email which is ending with ‘@yahoo.com’ and the other has a different email, then the one with the ‘@yahoo.com’ email should be discarded.

what would be best way to get this data out?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:15:58+00:00Added an answer on May 11, 2026 at 8:15 am

    Okay, I’m not going to get involved in yet another fight with those who say I shouldn’t advocate database schema changes (yes, you know who you are :-), but here’s how I’d do it.

    1/ If you absolutely cannot change the schema, I would solve it with code (either real honest-to-goodness procedural code outside the database or as a stored procedure in whatever language your DBMS permits).

    This would check the database for a non-yahoo name and return it, if there. If not there, it would attempt to return the yahoo name. If neither are there, it would return an empty data set.

    2/ If you can change the schema and you want an SQL query to do the work, here’s how I’d do it. Create a separate column in your table called CLASS which is expected to be set to 0 for non-yahoo addresses and 1 for yahoo addresses.

    Create insert/update triggers to examine each addition or change of a row, setting the CLASS based on the email address (what it ends in). This guarantees that CLASS will always be set correctly.

    When you query your table, order it by name and class, and only select the first row. This will give you the email address in the following preference: non-yahoo, yahoo, empty dataset.

    Something like:

    select name, email from tbl where name = '[name]' order by name, class fetch first row only; 

    If your DBMS doesn’t have an equivalent to the DB2 ‘fetch first row only’ clause, you’ll probably still need to write code to only process one record.

    If you want to process all names but only the specific desired email for that name, a program such as this will suffice (my views on trying to use a relational algebra such as SQL in a procedural way are pretty brutal, so I won’t inflict them on you here):

    # Get entire table contents sorted in name/class order. resultSet = execQuery 'select name, email from tbl order by name, class'  # Ensure different on first row lastName = resultSet.value['name'] + 'X'  # Process every single row returned. while not resultSet.endOfFile:     # Only process the first in each name group (lower classes are ignored).     if resultSet.value['name'] != lastName:         processRow resultSet.value['name'] resultSet.value['email']     # Store the last name so we can detect next name group.     lastName = resultSet.value['name'] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a simple table where the data is such that the rows
I have an Excel spreadsheet of some product data, (just a simple table) that
I have a very simple table with two columns, but has 4.5M rows. CREATE
I have a simple table (lets call it Table1) that has a NVARCHAR field
Say I have a simple table that contains username, firstname, lastname. How do I
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
I have a simple table that logs simple events an administrator does. Nothing complicated.
I have a very simple table called genre , which looks like this: GENRE
I just have a simple ASP Table seen here: <asp:Table ID=tblCategories runat=server CssClass=oneColTable padded-table
I have a simple app that has a list of clients in one table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.