473,412 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Help with Query

Hi,

I have the following table:

Column 1 Column 2
A A
A B
A C
B F
B F
C G
C A

I need a query to return the following:
A null
B F
C null

How can I do that?

Thanks,
ALex

Oct 13 '05 #1
3 1307
Why did you return an "F" for one row and NULL for the others? I'm
guessing that you only want to return a value in the second column
where that value is the same for every instance of the value in the
first column. I'm also guessing that both columns are not nullable in
your table (because you didn't specify any other columns that could be
a key). If that's correct, try this:

SELECT col1,
CASE WHEN MIN(col2)=MAX(col2) THEN MIN(col2) END AS col2
FROM your_table
GROUP BY col1;

(untested)

--
David Portas
SQL Server MVP
--

Oct 13 '05 #2
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.

After that ABSOLUTELY BASIC PIECE OF NETIQUETTE, did you read what you
posted? What the @!$% specs for this?? Wait, wait, let me read your
mind and guess that you want to see only those rows whose col_1 groups
have one and only one value for col_2 !!

SELECT F1.col1, F2.col2
FROM Foobar AS F1
LEFT OUTER JOIN
(SELECT col1, MIN(col2)
FROM Foobar
GROUP BY col1
HAVING MIN(col2) = MAX(col2))
AS F2 (col1, col2)
ON F1.col1 = F2.col1;

If you plan to stay in this trade, please learn minimal Netiquette and
how to write a minimal specification.

Oct 14 '05 #3
--CELKO-- (jc*******@earthlink.net) writes:
After that ABSOLUTELY BASIC PIECE OF NETIQUETTE, did you read what you
posted? What the @!$% specs for this?? Wait, wait, let me read your
mind and guess that you want to see only those rows whose col_1 groups
have one and only one value for col_2 !!
...
If you plan to stay in this trade, please learn minimal Netiquette and
how to write a minimal specification.


No, this is not what minimal nettiquette is about. Although, including
CREATE TABLE is nice, it's mainly a good idea, because it helps to
get a good answer.

But minimal and basic nettiquette is about something else: that is about
being polite and friendly. Something you are miserable poor in.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Oct 14 '05 #4

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

Similar topics

11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
5
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
3
by: mcmahonb | last post by:
Hey people... I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my...
4
by: n | last post by:
Hello! Here is a problem I hope you can point me to a solution. It Problem: A teacher needs to know which lesson to teach. A school has a curriculum with 26 lessons, A-Z. For a given class,...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.