Mysql Join / Union issue - mysql

I am trying to create a report that pulls data from 2 tables: a & b. The report is grouped by a.clock. Most of the data for the report comes from a - that part is working fine. a.clock links with b.userID.
The part i am struggling with is for one of the columns the data comes from b. I need to total up the following for each a.clock grouping in the main report (this query works standalone)
SELECT (
SUM(
TIME_TO_SEC(
TIMEDIFF(
CONCAT(b.endDate, ' ', b.outTime),
CONCAT(b.startDate, ' ', b.inTime)
)
) / 3600
)
) AS 'Misc Hours' FROM b
In other words, i need to total the Misc Hours (in b) for each a.clock. I thought maybe joining the b table was necessary but that didn't seem to work. Any suggestions?
Here are the table definitions (sorry, verbose)
CREATE TABLE `a` (
`laborID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`type` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '0=sched; 1=accepted; 2=complete; 3=authorize',
`laborType` varchar(15) NOT NULL DEFAULT '0' COMMENT 'Lookup',
`hours` varchar(15) NOT NULL DEFAULT '',
`wage` varchar(15) NOT NULL DEFAULT '',
`id` int(10) unsigned NOT NULL DEFAULT '0',
`laborDate` date NOT NULL,
`ot` varchar(15) NOT NULL,
`clock` varchar(15) NOT NULL,
`setup` varchar(15) NOT NULL DEFAULT '',
`ot2` varchar(15) NOT NULL,
`wageOT1` varchar(15) NOT NULL,
`wageOT2` varchar(15) NOT NULL,
`inTime` varchar(15) NOT NULL,
`outTime` varchar(15) NOT NULL,
`startDateString` varchar(125) NOT NULL,
`endDateString` varchar(125) NOT NULL,
`authRequestDate` datetime NOT NULL,
`authRequestUser` int(10) unsigned NOT NULL,
`authRequestReason` text NOT NULL,
`authDate` datetime NOT NULL,
`authUser` int(10) unsigned NOT NULL,
`authRequired` varchar(45) NOT NULL,
`km` varchar(45) NOT NULL,
`travelTime` varchar(45) NOT NULL,
`actualInTime` varchar(45) NOT NULL,
`actualOutTime` varchar(45) NOT NULL,
`actualKm` varchar(45) NOT NULL,
`actualTravelTime` varchar(45) NOT NULL,
`intNotes` text,
`extNotes` text,
`billableReason` text,
`billableHours` varchar(45) DEFAULT NULL,
`actualHours` varchar(45) DEFAULT NULL,
`overtime` varchar(45) DEFAULT NULL,
`followUpReason` text NOT NULL,
`responseType` varchar(45) DEFAULT NULL,
`followUpType` int(10) unsigned DEFAULT NULL,
`billableDrop` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`laborID`),
KEY `id` (`id`),
KEY `type` (`type`),
KEY `laborDate` (`laborDate`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
CREATE TABLE `b` (
`timecodeID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`userID` int(10) unsigned NOT NULL,
`inTime` varchar(45) NOT NULL,
`outTime` varchar(45) NOT NULL,
`startDateString` varchar(145) NOT NULL,
`endDateString` varchar(145) NOT NULL,
`startDate` varchar(45) NOT NULL,
`endDate` varchar(45) NOT NULL,
`type` varchar(45) NOT NULL,
`comments` text NOT NULL,
`multiDay` tinyint(3) unsigned NOT NULL,
PRIMARY KEY (`timecodeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Well if you have multiple rows in each of the table then you will get larger sum as each row in labor will join with each row in timecodes. So the idea is to have nested query group by clock and userid to get one row each as per the groupping
SELECT A.Clock, A.hours, B.'Misc Hours'
FROM
(
SELECT labor.clock,
SUM(hours) Hours
FROM labor
GROUP BY labor.clock
) A
INNER JOIN
(
SELECT timecodes.userID,
(SUM(
TIME_TO_SEC(
TIMEDIFF(
CONCAT(timecodes.endDate,' ',timecodes.outTime),
CONCAT(timecodes.startDate,' ',timecodes.inTime)
)
)/3600
)
) AS 'Misc Hours'
FROM timecodes
GROUP BY timecodes.userID
) AS B ON A.Clock = B.UserId

SELECT timecodes.userID,
(SUM(
TIME_TO_SEC(
TIMEDIFF(
CONCAT(timecodes.endDate,' ',timecodes.outTime),
CONCAT(timecodes.startDate,' ',timecodes.inTime)
)
)/3600
)
)
AS 'Misc Hours'
FROM timecodes WHERE timecodes.userID=labor.clock GROUP BY labor.clock

Related

Creating a summary from two tables?

I have two tables and I'm trying to create a summary with the sum of amount due per person but don't have the creative ID involved.
Table 1:
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Lname` varchar(255) NOT NULL,
`phone` varchar(15) NOT NULL,
`address` varchar(255) DEFAULT NULL,
`city` varchar(255) NOT NULL,
`state` char(2) NOT NULL,
`zip` varchar(50) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`business_name varchar(255) DEFAULT NULL,
Second table:
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`C_ID` INT(10) UNSIGNED NOT NULL,
`Amount_Due` DECIMAL(7 , 2 ) not null DEFAULT 0,
`created_date` DATETIME NOT NULL,
`closed_date` DATETIME default NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=LATIN1;
Here is what I'm trying to do:
I'm trying to make a summary with dates within 5/1/18 and 6/15/18.
Have the sum of due amount for each person
Have these aliases : Business name, Phone Number ,Invoiced Amounts
I'm trying to test my code but i'm getting errors:
SELECT Name,phone,SUM(Amount_Due) FROM test_customer,test_invoices
WHERE created_date BETWEEN '2018-05-01' AND "2018-06-15'
If I understand correctly, you need to use JOIN instead of ,(CROSS JOIN) and GROUP BY in non-aggregate function columns.
SELECT Name 'Customer Name',
phone 'Phone number',
SUM(i.Amount_Due) 'Amount due'
FROM test_customer c
INNER JOIN test_invoices i ON C.id = i.C_ID
GROUP BY Name,phone
sqlfiddle

Select items from 3 different tables

I would like to select items from 3 different tables, I am using UNION, but the number of columns is different, so it returns an error of number of columns, is there any other way using JOIN to get an appreciated result?
SELECT *
FROM `ads` JOIN ad_car
ON ads.id_ads = ad_car.main_ad
WHERE ads_cat = :ads_cat AND
ads.ad_status = :adStatus
UNION
SELECT *
FROM `ads` JOIN ad_vehpro
ON ads.id_ads = ad_vehpro.main_ad
WHERE ads_cat = :ads_cat AND
ads.ad_status = :adStatus
ORDER BY date_renewed
DESC LIMIT 4
EDITED: I add the tables:
CREATE TABLE IF NOT EXISTS `ads` (
`id_ads` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_profiles_key` varchar(20) NOT NULL,
`id_shops` int(4) NOT NULL DEFAULT '1',
`ads_cat` int(2) NOT NULL COMMENT 'main category: vehicule, immobilier,...',
`ads_scat` int(3) NOT NULL COMMENT 'sous cat: voiture, moto,...',
`form_id` varchar(30) NOT NULL COMMENT 'form key',
`city_id` int(5) NOT NULL,
`district_id` int(5) NOT NULL,
`adtype_id` int(1) NOT NULL DEFAULT '1' COMMENT '1: offre, 2: demande',
`ads_title` varchar(200) NOT NULL,
`ads_description` longtext NOT NULL,
`ads_price` int(11) NOT NULL,
`num_img` int(2) NOT NULL DEFAULT '1' COMMENT 'number of images',
`num_vid` int(2) NOT NULL DEFAULT '0' COMMENT 'number of video',
`num_com` int(3) NOT NULL DEFAULT '0' COMMENT 'number of comments',
`to_pin` int(1) NOT NULL DEFAULT '0' COMMENT 'ad that will be pinned. 0: no, 1: yes',
`date_inserted` varchar(20) NOT NULL,
`date_modified` varchar(20) NOT NULL,
`date_renewed` varchar(20) NOT NULL,
`date_pinned` varchar(20) NOT NULL DEFAULT '0',
`ad_status` int(1) NOT NULL DEFAULT '1' COMMENT '0: not active, 1: active, 2: deleted, 3: pinned',
PRIMARY KEY (`id_ads`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
CREATE TABLE IF NOT EXISTS `ad_car` (
`id_ad` int(10) unsigned NOT NULL AUTO_INCREMENT,
`main_ad` int(5) NOT NULL COMMENT 'this will refer to main table ads (id_ads)',
`id_profiles` varchar(20) NOT NULL,
`city_id` int(5) NOT NULL,
`district_id` int(5) NOT NULL COMMENT 'district id from districts table',
`category_id` int(2) NOT NULL,
`make_id` int(5) NOT NULL,
`model_id` int(5) NOT NULL,
`model_year` int(4) NOT NULL,
`engine` int(2) NOT NULL,
`fuel` int(1) NOT NULL,
`mileage` bigint(7) NOT NULL,
`transmission` int(1) NOT NULL,
`wheed_drive` int(1) NOT NULL,
`in_color` varchar(7) NOT NULL,
`ex_color` varchar(7) NOT NULL,
`seats` int(2) NOT NULL,
`doors` int(1) NOT NULL,
`tax` varchar(5) NOT NULL,
`warranty` int(1) NOT NULL,
`hands` int(1) NOT NULL,
`security` longtext NOT NULL,
`comfort` longtext NOT NULL,
`aesthetic` longtext NOT NULL,
`adreference` varchar(10) NOT NULL,
`ad_price` bigint(20) NOT NULL,
`ad_priceneg` int(1) NOT NULL,
`when_inserted` varchar(20) NOT NULL,
`when_modified` varchar(20) NOT NULL,
`ad_status` int(1) NOT NULL DEFAULT '1' COMMENT '0: not active, 1: active, 2: deleted',
`not_listed` longtext NOT NULL,
PRIMARY KEY (`id_ad`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
CREATE TABLE IF NOT EXISTS `ad_vehpro` (
`id_ad` int(10) unsigned NOT NULL AUTO_INCREMENT,
`main_ad` int(5) NOT NULL COMMENT 'this will refer to main table ads (id_ads)',
`id_profiles` varchar(20) NOT NULL,
`city_id` int(5) NOT NULL,
`district_id` int(5) NOT NULL COMMENT 'district id from districts table',
`category_id` int(2) NOT NULL,
`vehpro_type` int(1) NOT NULL,
`make_id` int(5) NOT NULL,
`model_id` int(5) NOT NULL,
`model_year` int(4) NOT NULL,
`engine` int(2) NOT NULL,
`fuel` int(1) NOT NULL,
`mileage` bigint(7) NOT NULL,
`transmission` int(1) NOT NULL,
`wheed_drive` int(1) NOT NULL,
`in_color` varchar(7) NOT NULL,
`ex_color` varchar(7) NOT NULL,
`seats` int(2) NOT NULL,
`doors` int(1) NOT NULL,
`tax` varchar(5) NOT NULL,
`warranty` int(1) NOT NULL,
`hands` int(1) NOT NULL,
`security` longtext NOT NULL,
`comfort` longtext NOT NULL,
`aesthetic` longtext NOT NULL,
`adreference` varchar(10) NOT NULL,
`ad_price` bigint(20) NOT NULL,
`ad_priceneg` int(1) NOT NULL,
`when_inserted` varchar(20) NOT NULL,
`when_modified` varchar(20) NOT NULL,
`ad_status` int(1) NOT NULL DEFAULT '1' COMMENT '0: not active, 1: active, 2: deleted',
`not_listed` longtext NOT NULL,
PRIMARY KEY (`id_ad`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
EDITED
I tried using LEFT JOIN but, it skips some fields:
$sqlAds = "SELECT * FROM `ads`"
. " LEFT JOIN ad_car ON ads.id_ads = ad_car.main_ad"
. " LEFT JOIN ad_vehpro ON ads.id_ads = ad_vehpro.main_ad"
. " WHERE ads_cat = :ads_cat AND ads.ad_status = :adStatus ORDER BY date_renewed DESC";
Thanks in advance
List the columns you explicitly want. Provide NULLvalues for the rest:
SELECT a.*, c.col1, c.col2
FROM `ads` a JOIN
ad_car c
ON a.id_ads = c.main_ad
WHERE ads_cat = :ads_cat AND
a.ad_status = :adStatus
UNION
SELECT a.*, v.col1, NULL as col2
FROM ads a JOIN
ad_vehpro v
ON a.id_ads = v.main_ad
WHERE ads_cat = :ads_cat AND
a.ad_status = :adStatus
ORDER BY date_renewed DESC
LIMIT 4;
Note: If you know there are no duplicates between the two subqueries, use UNION ALL rather than UNION. UNION incurs the overhead of removing duplicates.

mysql query to fetch records from multiple tables and join

I have 5 tables named: schools, candidates, candidate_subjects, subjects, lgas
Each school belong to a lga, each candidate belong to a school, each candidate registers subjects
Below are the table structures:
CREATE TABLE `subjects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
`code` varchar(10) DEFAULT NULL,
`exam_type_id` int(11) DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`type` varchar(3) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=60 DEFAULT CHARSET=latin1;
CREATE TABLE `candidates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`exam_no` varchar(20) DEFAULT NULL,
`surname` varchar(100) DEFAULT NULL,
`other_names` varchar(150) DEFAULT NULL,
`school_id` int(11) DEFAULT NULL,
`exam_type_id` int(11) DEFAULT NULL,
`dob` varchar(12) DEFAULT NULL,
`sex` varchar(6) DEFAULT NULL,
`no_of_subjects` int(2) DEFAULT NULL,
`nationality` varchar(20) DEFAULT NULL,
`state` varchar(20) DEFAULT NULL,
`lga` varchar(20) DEFAULT NULL,
`exam_year` varchar(4) DEFAULT NULL,
`date_created` varchar(255) DEFAULT NULL,
`date_modified` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`registration_completed` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28034 DEFAULT CHARSET=latin1;
CREATE TABLE `candidate_subjects` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`candidate_id` int(11) DEFAULT NULL,
`exam_type_id` int(10) DEFAULT NULL,
`subject_id` int(10) DEFAULT NULL,
`ca_score` int(11) DEFAULT NULL,
`exam_score` int(6) DEFAULT NULL,
`score_grade` varchar(10) DEFAULT NULL,
`date_created` varchar(10) DEFAULT NULL,
`date_modified` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=327740 DEFAULT CHARSET=latin1;
CREATE TABLE `schools` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`passcode` varchar(15) DEFAULT NULL,
`code` varchar(10) DEFAULT NULL,
`name` varchar(200) DEFAULT NULL,
`lga` int(11) DEFAULT NULL,
`address` varchar(250) DEFAULT NULL,
`phone` varchar(50) DEFAULT NULL,
`exam_year` varchar(10) DEFAULT NULL,
`eo_name` varchar(100) DEFAULT NULL,
`eo_phone` varchar(50) DEFAULT NULL,
`eo_email` varchar(100) DEFAULT NULL,
`date_created` varchar(10) DEFAULT NULL,
`date_modified` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`profile_created` int(1) DEFAULT NULL,
`entries_purchased` int(11) DEFAULT NULL,
`entries_used` int(11) DEFAULT NULL,
`entries_remaining` int(11) DEFAULT NULL,
`scratchcard_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=652 DEFAULT CHARSET=latin1;
CREATE TABLE `lgas` (
`lga_id` int(11) NOT NULL AUTO_INCREMENT,
`lga_name` varchar(250) NOT NULL,
`state_id` varchar(20) NOT NULL,
PRIMARY KEY (`lga_id`)
) ENGINE=InnoDB AUTO_INCREMENT=786 DEFAULT CHARSET=latin1;
I want to generate a report for each lga like this:
S/No| Name of School |Eng|Mth|B.sc|....Total registered
That is name of school from the selected lga, total number of students from that school that registered for Eng, Mth, B.sc ... Total number of students that registered those subjects from that school
SELECT
b.name as school_name,
sum(case when e.name = 'Eng' then 1 else 0 end) as english_students,
sum(case when e.name = 'Mth' then 1 else 0 end) as math_students,
sum(case when e.name = 'B.sc' then 1 else 0 end) as whatever_this_is_students
FROM lgas a
LEFT JOIN schools b ON a.lga_id = b.lga
LEFT JOIN candidates c on b.id = c.school_id
LEFT JOIN candidate_subjects d on c.id = d.candidate_id
LEFT JOIN subjects e on d.subject_id = e.id
WHERE a.lda_id = 'selected_id'
GROUP by school_name;

MySQL find a row when the sum of points become bigger than number

I have such sql query
SELECT *,(p.datetime-u.createtime)/86400 as result
FROM tbl_user_points p
Inner join tbl_users u ON u.id=p.user_id
GROUP BY p.user_id
HAVING SUM(p.points) > 100
order by SUM(p.points)
i need to find the datetime( the row in table tbl_user_points), when each users reached.
For more information Here the schemata of table
tbl_user_points
CREATE TABLE `tbl_user_points` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`action` int(10) unsigned NOT NULL,
`description` varchar(255) DEFAULT '',
`points` int(10) NOT NULL DEFAULT '0',
`datetime` int(10) unsigned NOT NULL,
`club_id` int(10) unsigned DEFAULT NULL,
`event_id` int(10) unsigned DEFAULT NULL,
`location_id` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='Achieved users points for any actions.';
Here the schemata of table
tbl_users
CREATE TABLE `tbl_users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`email` varchar(128) NOT NULL,
`activkey` varchar(128) NOT NULL DEFAULT '',
`createtime` int(11) NOT NULL,
`lastvisit` int(11) NOT NULL,
`superuser` int(1) NOT NULL DEFAULT '0',
`status` int(1) NOT NULL DEFAULT '1',
`first_name` varchar(128) DEFAULT NULL,
`last_name` varchar(128) DEFAULT NULL,
`gender` varchar(6) DEFAULT NULL,
`locale` varchar(45) DEFAULT NULL,
`service` varchar(45) NOT NULL,
`service_id` varchar(255) DEFAULT NULL,
`location` varchar(128) DEFAULT NULL,
`state` int(3) DEFAULT NULL,
`photo` varchar(255) DEFAULT NULL,
`city` varchar(125) DEFAULT NULL,
`about_me` varchar(255) DEFAULT NULL,
`user_code` varchar(10) DEFAULT NULL,
`loyalty_level` varchar(45) DEFAULT 'basic' COMMENT 'Level of loyalty for current user',
`updatetime` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `user_code_UNIQUE` (`user_code`),
KEY `status` (`status`),
KEY `superuser` (`superuser`)
) ENGINE=InnoDB AUTO_INCREMENT=1033 DEFAULT CHARSET=utf8;
sample input
tbl_user_points
id | user_id|action|description|points| datetime
2246 1 1 First visit 5 1383331212
2254 1 2 Second visit 15 1383354853
2255 1 3 Winner 25 1383360231
2256 2 1 First visit 5 1383331202
2257 2 2 Second visit 15 1383354553
2258 2 3 Winner 25 1383360211
tbl_user simple,for example
id=1,createtime=1313000000
id=2,createtime=1313000001
for HAVING SUM(p.points) > 15
output should be
user_id datetime
1 1383354853
2 1383354553
Use CASE syntax. Check this link:
http://dev.mysql.com/doc/refman/5.0/en/case.html.
You can achieve it by using statements like this:
Select X, case when y>100 then desired_row when y<100 then desired_row end as 'desired_row' from your_table where column=your_condition order by 1
Here you're conditioning the select clause by as many cases or conditions you requiere.

MySQL - Counting a count?

I'm trying to aggregate some data I've pulled from my MySQL db.
Query I'm using is:
SELECT `PUID`,`DROID_V`,`SIG_V`,`SPEED`,
COUNT(distinct IF(sourcelist.hasExtension=1,NAME,NULL)) as Ext,
COUNT(distinct IF(sourcelist.hasExtension=0,NAME,NULL)) as NoExt,
COUNT(distinct NAME) as `All`
FROM sourcelist, main_small
WHERE sourcelist.SourcePUID = 'My_Variable' AND main_small.NAME = sourcelist.SourceFileName
GROUP BY `PUID`,`DROID_V`,`SIG_V`,`SPEED` ORDER BY `DROID_V` ASC, `SIG_V` ASC, `SPEED`
And I wondered if there was a way of counting this result, so I can make a new table that would show me something like:
Every distinct PUID, (count of distinct DROID_V), (count of distinct Sig_V), (SUM of total hits for NAME) WHERE sourcelist.SourcePUID = 'My_Variable' AND main_small.NAME = sourcelist.SourceFileName
As you can see, I'm really not very good at SQL!
Source table:
CREATE TABLE `t1` (
`DROID_V` int(1) DEFAULT NULL,
`Sig_V` varchar(7) DEFAULT NULL,
`SPEED` varchar(4) DEFAULT NULL,
`ID` varchar(7) DEFAULT NULL,
`PARENT_ID` varchar(10) DEFAULT NULL,
`URI` varchar(10) DEFAULT NULL,
`FILE_PATH` varchar(68) DEFAULT NULL,
`NAME` varchar(17) DEFAULT NULL,
`METHOD` varchar(10) DEFAULT NULL,
`STATUS` varchar(14) DEFAULT NULL,
`SIZE` int(10) DEFAULT NULL,
`TYPE` varchar(10) DEFAULT NULL,
`EXT` varchar(4) DEFAULT NULL,
`LAST_MODIFIED` varchar(10) DEFAULT NULL,
`EXTENSION_MISMATCH` varchar(32) DEFAULT NULL,
`MD5_HASH` varchar(10) DEFAULT NULL,
`FORMAT_COUNT` varchar(10) DEFAULT NULL,
`PUID` varchar(15) DEFAULT NULL,
`MIME_TYPE` varchar(24) DEFAULT NULL,
`FORMAT_NAME` varchar(10) DEFAULT NULL,
`FORMAT_VERSION` varchar(10) DEFAULT NULL,
`INDEX` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`INDEX`)
) ENGINE=MyISAM AUTO_INCREMENT=960831 DEFAULT CHARSET=utf8
example records:
5;"v37";"slow";"10266";;"file:";"V1-FL425817.tif";"V1-FL425817.tif";"BINARY_SIG";"MultipleIdenti";"20603284";"FILE";"tif";"2008-11-03";;;;"fmt/7";"image/tiff";"Tagged Ima";"3";"191977"
5;"v37";"slow";"10268";;"file:";"V1-FL425817.tif";"V1-FL425817.tif";"BINARY_SIG";"MultipleIdenti";"20603284";"FILE";"tif";"2008-11-03";;;;"fmt/8";"image/tiff";"Tagged Ima";"4";"191978"
5;"v37";"slow";"10269";;"file:";"V1-FL425817.tif";"V1-FL425817.tif";"BINARY_SIG";"MultipleIdenti";"20603284";"FILE";"tif";"2008-11-03";;;;"fmt/9";"image/tiff";"Tagged Ima";"5";"191979"
5;"v37";"slow";"10270";;"file:";"V1-FL425817.tif";"V1-FL425817.tif";"BINARY_SIG";"MultipleIdenti";"20603284";"FILE";"tif";"2008-11-03";;;;"fmt/10";"image/tiff";"Tagged Ima";"6";"191980"
Sure just do something like
Select Count(*) From (Select * From SomeTable) adummynamesoSqlParserDoesntgetupset
so put your query in parentheses after FROM give it a unique name, and you can treat it like a table or a view.