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
https://forums.phpfreaks.com/topic/38843-unique-query/
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
https://forums.phpfreaks.com/topic/38843-unique-query/#findComment-186767
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.