Jump to content

Unique Query


CanMan2004

Recommended Posts

Hi all

 

I have a table which looks like

 

id dmid pgid

43 14 56

10 9 6

26 7 21

42 22 6

 

I want to write a query which returns all rows, but groups them.

 

For example, with the above data, it would return 3 rows, because there is 2 rows which have the same pgid, so that is classed as 1 row.

 

So the query should return

 

pgid: 6

pgid: 21

pgid: 56

 

but then I want to print under each row, the dmid value for each row in the database, for example

 

pgid: 6

dmid: 9

dmid: 22

 

pgid: 21

dmid: 7

 

pgid: 56

dmid: 14

 

Does that make sense? Can anyone help?

 

Thanks in advance

 

Ed

Link to comment
Share on other sites

You have two different questions, because you can't use GROUP BY and expect the dmid values to be given to you. GROUP BY gives you unique record, so any matching records will not be included. You can do what you want via scripting! If thats ok, tell me I'll give you an example.

 

printf

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.