I’m trying to build a SQL that will return the total amount of file for all the events.
DB:
id | name | filename1 | filename2
1 event1 1.jpg 2.jpg
2 event2 1.jpg Null
If you look at this scenario it should return “You have 3 files” but I have no idea how to make the SQL.
I’m using mySQL.
Thanks
You can unpivot or use
UNION ALLon the data in thefilename1andfilename2fields and then get a total count. TheUNION ALLtakes the data from the multiple columns and converts it into multiple rows:See SQL Fiddle with Demo