HI I am trying to group some results by a visit_id, however it just doesn't seem to work.
Here is my code.
SELECT url1 FROM pages GROUP BY visit_id ORDER BY timedate
Here is my database structure
id` int(10) NOT NULL AUTO_INCREMENT,
`client_id` int(11) NOT NULL,
`url` text NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`timedate` datetime NOT NULL,
`visit_id` varchar(100) NOT NULL,
`url1` varchar(255) NOT NULL,
`page_time` time NOT NULL
The code works it just doesn't seem to group by id
This is a guess. The guess is that you want all url1
for a given visit_id
"grouped" together. If so, use group_concat()
:
SELECT visit_id, group_concat(url1 separator ', ' order by timedate)
FROM pages
GROUP BY visit_id
I also included visit_id
in the select
clause so you can see which visit corresponds to which pages. If you want a unique list, then use group_concat(distinct url1 . . .)
.