Jump to content

using distinct


jeff5656

Recommended Posts

I want to select records with DISTINCT only records with payment_type of a certain type are displayed once:

 

$query = "select distinct payment_type  from payments ";

 

So if I have payment_types of "A", "B" and "C"

each of those 3 will only be displayed once and not repeated.  The problem is, how do I SELECT more fields from each record?  I tried

$query = "select distinct payment_type, *  from payments ";

but that didn't work.

 

Link to comment
Share on other sites

Also, don't use * unless you really do need all the columns.

 

I hear that is also a good idea to list the fields in the order they are in the database skipping the ones not needed. I could be wrong but that is what I heard.

Haven't heard of that, do you know for what reason(s)?

Link to comment
Share on other sites

I was told it was faster. I assume it is so MySQL doesn't have to reorder columns/data, it would just get the columns/data as is without having to reorder it.

Interesting.  I guess it makes sense, I'll have to check it out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.