user188962
user188962

Reputation:

Another rookie question; How to implement Count() here?

I have this query:

SELECT mt.*, fordon.*, boende.*, elektronik.*, business.*, hem_inredning.*, hobby.*
FROM classified mt 
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id 
LEFT JOIN boende ON boende.classified_id = mt.classified_id 
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id 
LEFT JOIN business ON business.classified_id = mt.classified_id 
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id 
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id 
ORDER BY modify_date DESC

I need to implement a count here, to just count all rows in combination with the JOINS you see.

How should I do this?

SELECT COUNT(mt.*, fordon.* etc) FROM ? // This method wont work

Thanks

Upvotes: 0

Views: 136

Answers (4)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171411

I removed the ORDER BY, as it is not required for the COUNT:

SELECT count(*)
FROM classified mt  
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id  
LEFT JOIN boende ON boende.classified_id = mt.classified_id  
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id  
LEFT JOIN business ON business.classified_id = mt.classified_id  
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id  
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id 

Upvotes: 3

treznik
treznik

Reputation: 8124

How about SELECT COUNT(*) FROM ... ? I'm not sure what you're trying to count.

Upvotes: 0

Marijn van Vliet
Marijn van Vliet

Reputation: 5399

How about simply:

SELECT COUNT(*) FROM ...

Upvotes: 0

Leslie
Leslie

Reputation: 3644

SELECT COUNT(*) FROM (SELECT mt.*, fordon.*, boende.*, elektronik.*, business.*,     hem_inredning.*, hobby.*
FROM classified mt 
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id 
LEFT JOIN boende ON boende.classified_id = mt.classified_id 
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id 
LEFT JOIN business ON business.classified_id = mt.classified_id 
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id 
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id) As A

Upvotes: 1

Related Questions