473,396 Members | 1,725 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,396 software developers and data experts.

help with a select clause

We have a recordset with the following structure id (int), mls
(varchar)

What we need to do is within a single sql call we need to show all
records where the mls = '' and all unique records where mls!=''

In other words, there will be multiple records with duplicate mls
entries. We do not want to show duplicate enties for where the mls has
been set, only where the mls has not been set.

Any suggestions?

Dec 30 '05 #1
2 1298
I'm not sure I understand the question here. It sounds like you want
to do 2 queries (one where MLS is = something and one where MLS !=
something). Is that correct?

In that case you could just use a union to perform the 2 queries and
return them.

select mls, id from mls_id_table where mls='value' union select
distinct mls, id from mls_id_table where mls != 'novalue';

If you are looking for distinct values across the board you might try:

select distinct A.mls, A.id from (select mls_id_table where mls='value'
union select distinct mls, id from mls_id_table where mls != 'novalue')
as A;

To ensure you get adequate performance you might need to make sure your
sort buffer is of adequate size (EXPLAIN the query to find out)..
Otherwise you might find that the queries that use sort will have to
work with a temporary table..

--
Chander Ganesan
Open Technology Group, Inc.
Phone: 877-258-8987/919-463-0999
http://www.otg-nc.com
Expert MySQL training.

Dec 30 '05 #2
Thanks! I completely forgot about Union and intersect! but that's is
what I was hunting for.

Kudos!

Lone Wolf

Dec 30 '05 #3

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

Similar topics

3
by: Robby McGehee | last post by:
I need this to work: SELECT FROM WITH (NOLOCK) where ='a' GROUP BY , HAVING COUNT () > 1 The problem is that I get an error that needs to be in the GROUP BY clause or aggregate function. if...
5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
17
by: the other john | last post by:
This should be fairly basic but I can't think of how to do this and I'm running out of time! I am developing a picture gallery and I can't figure out how to select "one" picture from each...
2
by: aj70000 | last post by:
This is my query select ano,max(date),a_subject from MY_TAB where table_name='xyz' and ano=877 group by a_subject,ano order by a_subject ANO max(Date) A_Subject 877 2005-01-20...
6
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid,...
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...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Jerry | last post by:
I am a MySQL and PHP newbie. I am having trouble getting the $w variable in my code below passed to mysql. When I use the value of $w directly in the Where clause, the correct rows are returned....
3
by: rogynskyy | last post by:
Hi guys, I'm running MSDE 2000 A on Win XP I've got a database with several tables, all of the tables display data in query manager. I wrote this simple query: Select
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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,...

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.