473,657 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

distinct with multiple field

7 New Member
my $cStr="select distinct artist,company from albuminfo ";


i am using this query to select unique artist and company. But the duplicates also get display.

Is any idea.

Thanks
Aug 2 '07 #1
11 7680
dafodil
392 Contributor
select distinct artist, company from albuminfo
your mysql code up there means that there will be distinct artist and company not distinct artist and distinct company.
For example:
Artist--------Company
----------------------------------------
Artist A------Company B
Artist A---- - Company C
Artist A-------Company D
Artist B-------Company A
Artist C-------Company A

Try this first:
select distinct artist from albuminfo
so that you can check whether distinct really works.
If it works, the problem might be in the way you put the command
Aug 2 '07 #2
siva07
7 New Member
Thanks for your reply,

I have tried to select only the distinct artist,its working.but if i select both artist and company it gives duplicate records.

is any idea.
Aug 2 '07 #3
mwasif
802 Recognized Expert Contributor
Did you really understand what dafodil told?

What you wanted to display if you have the following data in the table?

Artist--------Company
----------------------------------------
Artist A------Company B
Artist A---- - Company C
Artist A-------Company D
Artist B-------Company A
Artist C-------Company A

Do you want to select Artist A only once regardless of the company? If this is you are looking for then use GROUP BY instead
Expand|Select|Wrap|Line Numbers
  1. SELECT artist,company FROM albuminfo GROUP BY artist
Aug 2 '07 #4
dafodil
392 Contributor
Try this:
Expand|Select|Wrap|Line Numbers
  1. SELECT distinct artist, company FROM albuminfo group by artist

If it doesen't work give me a sample of what would you want to display just like my sample on my previous posts.

Sorry I'm still editting my post when you posted I can't delete this anymore.
try it.

Moderator: Kindly use code tags when posting source code.
Aug 2 '07 #5
rajiv07
141 New Member
Thank u,
Let me Explain with Sample,

My table name Is ALBUMINFO

Assume It has two fields called ARTIST and COMPANY

ARTIST --------------------------------------> COMPANY
A1 ------------------------------------------> C1
A1 -------------------------------------------> C1
A2--------------------------------------------> C2
A2 ------------------------------------------> C2
A2 ------------------------------------------> C3
A2 ------------------------------------------> C3
Ok,Now i want output ike this

ARTIST---> A1 and A2
COMPANY-->C1 and C2 and C3
Aug 2 '07 #6
mwasif
802 Recognized Expert Contributor
How will you know that which Artist belongs to which company?
Aug 2 '07 #7
dafodil
392 Contributor
Yeah that's right it should be by pair.. In the first place, you should have created a table with a primary key as artist and a unique key as company, if you want to totally sort them out.
Aug 2 '07 #8
mwasif
802 Recognized Expert Contributor
You can also use GROUP_CONCAT().
Aug 2 '07 #9
rajiv07
141 New Member
Table ALBUMINFO

ID---ARTIST --------------------------------------> COMPANY
1----A1 ------------------------------------------> C1
2----A1 -------------------------------------------> C1
3----A2--------------------------------------------> C2
4----A2 ------------------------------------------> C2
5----A2 ------------------------------------------> C3
6----A2 ------------------------------------------> C3



here i am using ID as a primary Key.


my $cStr="select distinct artist from albuminfo ";

my $cStr1="select distinct company from albuminfo ";

Suppose, i use these Query in two steps

The OutPut Will be

ARTIST

A1,A2

and

COMPANY

C1,C2,C3

If i am right,Then i want impelment these two Query into one compained query.
for the Same above Output.

Is Any Idea.
Aug 2 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6255
by: Ralph Freshour | last post by:
I have a question about the following PHP script - I got it off a web site tutorial on how to count users logged into your site - my question is the $PHP_SELF variable - it writes the name of the web page to the 'file' field in the table - I don't understand why it is doing that - I mean, isn't the SELECT DISTINCT statement only pulling those records from that one web page? I guess I just don't follow what it is doing with that SELECT...
6
10890
by: Dianna | last post by:
I don't understand why the dataview or the dataset does not have a 'Select Distinct' option. They both can do so much to filter the data except that. The article Microsoft has 326176 works, but not if you need to select distinct on multiple fields. Does anyone have any suggestions Thanks Diann
2
12542
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an "Column 'authors' in field list is ambiguous" error. Is there also a query to return only the count of distinct authors from the two tables? Thanks for any help.
1
14481
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT aggregate function, but there is no reference, at least that I can find anywhere, of how to do this. I have multiple lines fields for which I would like to do a "count distinct", but for simplicity, I am showing an example of only one field. Here is...
5
53394
by: Fred Zuckerman | last post by:
Can someone explain the difference between these 2 queries? "Select Distinct id, account, lastname, firstname from table1" and "Select DistinctRow id, account, lastname, firstname from table1" Thanks, Fred Zuckerman
2
1464
by: ray well | last post by:
i have to extract info from a legacy access database, which i can't alter, or run APPEND or UPDATE quries against. i can only use SELECT statments to extract what i need. the database has multiple entries for the same first and last name, i need to generate a dataset that has no duplicate first and last names. the sql statment itself is quite easy SELECT DISTINCT tblNameAndAddress.LastName, tblNameAndAddress.FirstName
2
3691
by: krishnan | last post by:
Dear all, In SQL Server 2000 , how to get distinct records sort by one field . Example SELECT DISTINCT A FROM tblTEST ORBER BY B Here, In Table
2
5336
by: Techhead | last post by:
I need to run a SELECT DISTINCT query across multiple fields, but I need to add another field that is NON-DISTINCT to my record set. Here is my query: SELECT DISTINCT lastname, firstname, middleinitial, address1, address2, city, state, zip, age, gender FROM gpresults
4
29975
by: Lacutas | last post by:
Hi all, I am having some problems using LINQ to access Distinct records from a Dataset. I have looked around and believe it should be as simple as added .Distinct() to my LINQ query below, though intellisense doesn't even give that option! My DataSet has multiple tables, all populated with data. I have a table called DemographicCriteria which has the fields listed below. CriteriaID DemographicCode InputID
17
12478
by: ukchat | last post by:
I.m creating a dynamic query to pull out workbooks from my database the table structure is below. Table: curricworkbooks Columns: ID, curric, assessment, topic, workbook, filename Example data 1 N1/E1.1 Numeracy E1 Count 1 workbooks/Num Entry 1/Unit 1/04 N1E1.1-3 Worksheets Num.pdf 10 MSS1/E1.6 Numeracy E1 Capacity 13 workbooks/Num Entry 1/Unit 13/04 MSS1E1.6 Worksheets Num.pdf
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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 we have to send another system
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.