0

Table structure:

id, UserID, packid, value

Sample data:

id      UserID      packid      value
______________________________________
1       1           5           3.27105
2       1           5           3.27105
3       1           5           3.27105
4       1           5           3.27105
5       1           10          3.27105
6       1           10          3.27105
7       1           10          3.27105
8       1           10          3.27105
9       2           5           3.27105
10      2           5           3.27105
11      2           5           3.27105
12      2           10          3.27105
13      2           10          3.27105
14      2           10          3.27105

Note: The values will be different for each row, this is dummy data.

I need to select first row against an id form the table in mysql using php. I am currently using this query with php while loop:

select * from tbl_userroi where UserID = '$UserIDs' ORDER BY id LIMIT 1

result:

UserID: 6 -> PackID: 1 ->> ROIValue: 3.27105
UserID: 2 -> PackID: 7 ->> ROIValue: 5.60309

Its working fine, but now I need to change the query little bit to get the record like if the userid '6' has same packid multiple times in the table, then I can get the first row of both packages values for the same user. Like this:

expected result:

UserID: 6 -> PackID: 1 ->> ROIValue: 3.27105
UserID: 6 -> PackID: 2 ->> ROIValue: 1.09501
UserID: 2 -> PackID: 7 ->> ROIValue: 5.60309

Now the above mentioned expected result I need. What will be the query for getting such kind of data?

Muhammad Noman
  • 155
  • 1
  • 5
  • 12

0 Answers0