Jump to content

joined table counting and all of first tabel return records sql help


Recommended Posts

hi guys

 

im joing 2 tables onto a users and then joining another table onto them tables and then i want all the users and then a count of all there observations and a count of all the uploaded images for that observation.

 

 

SELECT 
	u.username AS Username, 
	u.id AS 'User ID', 
	u.title AS 'Title', 
	u.forename AS 'First Name', 
	u.surname AS 'Last Name', 
	u.address1 AS 'Address Line 1', 
	u.address2 AS 'Address Line 2', 
	u.town AS 'Town/City', 
	c.title AS 'County', 
	u.postcode AS 'Postcode', 
	u.age AS 'Age', 
	u.youth_name AS 'School Name', 
	count(i.observation_id) AS 'Number Of Uploads', 
	count(o.id) AS 'Number Of Identifications', 
	CASE WHEN u.ispot = 1 
		THEN 'No' 
		ELSE 'Yes' END AS 'Mailing List Subscribed (Yes\No)',
	u.email AS 'Email Address'
FROM user u
LEFT JOIN (observation o, county c, image i)
ON (u.id = o.user_id AND u.county_id = c.id AND i.observation_id = o.id) 
WHERE 
	1=1 
	{$from_to_filter}
	{$subscribed_filter} 
GROUP BY o.user_id 

 

its just not working out in order to count i have to use group by and that makes the 1300 users turn into 230 for some reason ???????????

 

 

any help suggestions would be very much appreciated

 

thanks

  • 2 weeks later...
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.