Jump to content

Sql Distinct


harshpandya
 Share

Recommended Posts

Hi Guys here is my query select DISTINCT login.guest_id,login.create_time, custom_brochure_register.al_id, custom_brochure_register.fname, custom_brochure_register.lnamefrom login, custom_brochure_registerwhere login.guest_id = custom_brochure_register.id and custom_brochure_register.al_id = 28order BY login.create_time What i really want to do isShow distinct value of the login.guest_id, but i also want to show login.create_time on the output but not distinct value of login.create_timeFor example if i do this it worksselect DISTINCT login.guest_id ,custom_brochure_register.al_id, custom_brochure_register.fname, custom_brochure_register.lnamefrom login, custom_brochure_registerwhere login.guest_id = custom_brochure_register.id and custom_brochure_register.al_id = 28order BY login.create_time note that i removed the login.Create_time but i want to show that create_time in my output as well, how do i do that Please help, Thanks

Link to comment
Share on other sites

That doesn't make sense. You're asking for distinct values from one field and a specific value from another field. Imagine if you had this data:

guest id	  create_time-------------------------1			 101			 201			 30

You've got 3 values for the same ID. So when you ask for distinct IDs, it's going to return 1. Which time is it going to return for that? Will it return 10 or 20 or 30? All of them apply. You're asking the database for ambiguous information, it doesn't know what you're asking for. It doesn't make sense to ask it for a distinct value and then one of the possible values for another column that relates to one of the records that includes that distinct value.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...