Executing a SQL file - mysql

I am very new to MySQL. I have an SQL file called tables.sql as shown below.
I uploaded it to a subfolder in my public_html folder.
When I copy the below into a MySQL query and run it, I get this error: "Documentation #1046 - No database selected".
How can I execute this to create a table? When I go to http://mywebsite.com/subfolder/tables.sql it says Page not found
CREATE TABLE IF NOT EXISTS `users` (
`id` int(100) NOT NULL AUTO_INCREMENT,
`fullname` varchar(200) NOT NULL,
`username` varchar(100) NOT NULL,
`email` varchar(200) NOT NULL,
`password` varchar(100) NOT NULL,
`gender` varchar(100) NOT NULL,
`photo` varchar(200) NOT NULL,
`businessname` text NOT NULL,
`telephone` varchar(200) NOT NULL,
`country` varchar(100) NOT NULL,
`confirmed` varchar(100) NOT NULL,
`registered_date` varchar(200) NOT NULL,
`last_visited` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
INSERT INTO `users` (`id`, `fullname`, `username`, `email`, `password`, `gender`, `photo`, `businessname`, `telephone`, `country`, `confirmed`, `registered_date`, `last_visited`) VALUES
(1, 'Vasplus Blog', 'vasplus', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'vasplus.gif', 'Vasplus Programming Blog', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013'),
(2, 'Victor Olu', 'victor', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'victor.gif', 'Vasplus Blog', '', 'Malaysia', 'yes', '05-05-2013', '05-05-2013'),
(3, 'Greg Joshua', 'greg', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'c.jpg', 'Vasplus Programming Blog', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013'),
(4, 'Emy Nero', 'pretty', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Female', 'd.jpg', 'Vasplus Programming Blog', '', 'Italy', 'yes', '05-05-2013', '05-05-2013'),
(5, 'Victor Barack', 'barack', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'b.jpg', '', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013'),
(6, 'Chin Shi Hong', 'chin', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'a.jpg', '', '', 'Malaysia', 'yes', '05-05-2013', '05-05-2013'),
(7, 'Sydney Odell', 'ney', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Female', 'e.jpg', '', '', 'China', 'yes', '05-05-2013', '05-05-2013'),
(8, 'Engineer Bob', 'bobby', 'vasplusblog#gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'bobby.jpg', '', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013');
CREATE TABLE IF NOT EXISTS `vpb_pms` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`touser` varchar(40) NOT NULL,
`fromuser` varchar(40) NOT NULL,
`subject` text NOT NULL,
`message` text NOT NULL,
`read` enum('0','1') NOT NULL DEFAULT '0',
`deleted` enum('0','1') NOT NULL DEFAULT '0',
`datesent` varchar(200) NOT NULL,
`outdel` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `vpb_pms_attachments_main` (
`id` int(100) NOT NULL AUTO_INCREMENT,
`uid` varchar(200) NOT NULL,
`from` varchar(200) NOT NULL,
`to` varchar(200) NOT NULL,
`file` varchar(200) NOT NULL,
`date` varchar(200) NOT NULL,
`delete` varchar(200) NOT NULL,
`outdelete` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `vpb_pms_attachments_temporal` (
`id` int(100) NOT NULL AUTO_INCREMENT,
`uid` varchar(200) NOT NULL,
`from` varchar(200) NOT NULL,
`to` varchar(200) NOT NULL,
`file` varchar(200) NOT NULL,
`date` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Connect to the MySQL Client, and when you have authenticated yourself, and created the database (create database [database name];) then just execute the script with the command:
\. tables.sql

If your database was not created, create it first like this:
mysqladmin -uroot -p myRootPassword create myDatabaseName
If root has no password setup, forget the -p myRootPassword
Then run the following command from your the command line, being in your public_html folder:
mysql -u root -p myRootPassword mydatabaseName < tables.sql
Replace myRootPassword by your mysql root password and mydatabaseName by your database name.
If root has no password setup run it like this:
mysql -u root -p myRootPassword mydatabaseName < tables.sql

The geeky approach:
Step 1. Create your database:
mysql -h yourHost -u yourUser -pYourPassword -e"create database dbName";
(if you are working on localhost, you can omit the -h yourHost piece.
Step 2. Load your file on the newly created database:
mysql -h yourHost -u yourUser -pYourPassword dbName < tables.sql

Related

Join two tables where one table name is inside the other table

I am registering various properties in the property table. Depending on the type of property, three new tables namely apartment, villa, land is used to store specific data. So what I have is the a master table which holds property URL, Property type, Ref table name (any of the three sub table name - apartment, villa, land) and the ref id which is the primary autoincrement key of the sub tables.
I tried the three seperated select query and Union of the result. The drawback is that the results will be mostly from the first table name uses among the three.
function getMyProperty() {
$tables = $this->getPropertyTables();
$result = array();
foreach ($tables as $key => $table) {
$this->db->select('a.main_heading, a.sub_heading, a.location, a.about_property, a.property_price, a.available_from, p.property_url');
$this->db->from('property p');
$this->db->join($table . ' a', 'p.ref_id = a.id');
$this->db->where('p.posted_by', $this->session->user_id);
$this->db->where('p.ref_table', $this->db->dbprefix($table));
$query = $this->db->get();
$res = $query->result();
$result = array_merge($result, $res);
}
return $result;
}
DB SCHEMA
CREATE TABLE `apartment` (
`id` int(11) NOT NULL,
`main_heading` varchar(256) NOT NULL,
`sub_heading` text NOT NULL,
`build_up_area` int(11) NOT NULL,
`carpet_area` int(11) NOT NULL,
`no_of_bedrooms` int(11) NOT NULL,
`bathrooms` int(11) NOT NULL,
`available_from` date NOT NULL,
`furnishing` varchar(256) NOT NULL,
`facing` varchar(100) NOT NULL,
`flooring` varchar(256) NOT NULL,
`parking` varchar(256) NOT NULL,
`width_of_facing_road` varchar(100) NOT NULL,
`property_age` int(11) NOT NULL,
`property_price` decimal(16,2) NOT NULL DEFAULT '0.00',
`address` text NOT NULL,
`about_property` text NOT NULL,
`location` varchar(256) NOT NULL,
`amenities` text NOT NULL,
`owner_name` varchar(256) NOT NULL,
`owner_email` varchar(256) NOT NULL,
`owner_phone` varchar(100) NOT NULL,
`active` enum('Y','N') NOT NULL DEFAULT 'Y'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
INSERT INTO `apartment` (`id`, `main_heading`, `sub_heading`, `build_up_area`, `carpet_area`, `no_of_bedrooms`, `bathrooms`, `available_from`, `furnishing`, `facing`, `flooring`, `parking`, `width_of_facing_road`, `property_age`, `property_price`, `address`, `about_property`, `location`, `amenities`, `owner_name`, `owner_email`, `owner_phone`, `active`) VALUES
(2, 'My Appartment', 'Place', 255, 400, 4, 4, '2019-08-08', 'semi', 'north', 'vitrified', '2', '15', 15, '15.00', 'ghkgkgk', 'jkhjkhjk', 'Kochi', '', 'Agent', 'abc#edg.com', '9876543210', 'Y'),
(3, 'My Appartment 2', 'Test', 255, 400, 4, 4, '2019-08-08', 'semi', 'north', 'vitrified', '2', '15', 15, '15.00', 'ghkgkgk', 'jkhjkhjk', 'Kochi', '', 'Agent', 'abc#edg.com', '9876543210', 'Y');
CREATE TABLE `land` (
`id` int(11) NOT NULL,
`main_heading` varchar(256) NOT NULL,
`sub_heading` text NOT NULL,
`plot_area` int(11) NOT NULL,
`gated_colony` int(11) NOT NULL,
`open_sides` int(11) NOT NULL,
`available_from` date NOT NULL,
`dimensions` varchar(256) NOT NULL,
`facing` varchar(100) NOT NULL,
`boundary_wall` varchar(256) NOT NULL,
`parking` varchar(256) NOT NULL,
`width_of_facing_road` varchar(100) NOT NULL,
`property_age` int(11) NOT NULL,
`property_price` decimal(16,2) NOT NULL DEFAULT '0.00',
`address` text NOT NULL,
`about_property` text NOT NULL,
`location` varchar(256) NOT NULL,
`owner_name` varchar(256) NOT NULL,
`owner_email` varchar(256) NOT NULL,
`owner_phone` varchar(100) NOT NULL,
`active` tinyint(4) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
CREATE TABLE `property` (
`property_id` int(11) NOT NULL,
`posted_by` int(11) NOT NULL,
`post_type` enum('RENT','SELL','LEASE') NOT NULL,
`property_type` enum('VILLA','APARTMENT','LAND') NOT NULL,
`property_url` varchar(50) NOT NULL,
`ref_table` varchar(50) NOT NULL DEFAULT '',
`ref_id` int(11) NOT NULL DEFAULT '0',
`posted_on` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
INSERT INTO `property` (`property_id`, `posted_by`, `post_type`, `property_type`, `property_url`, `ref_table`, `ref_id`, `posted_on`) VALUES
(4, 1, 'SELL', 'VILLA', 'lyohlp', 'villa', 2, '2019-08-05'),
(5, 1, 'SELL', 'APARTMENT', 'cvbdit', 'apartment', 2, '2019-08-05'),
(6, 2, 'SELL', 'APARTMENT', 'qwerty', 'apartment', 3, '2019-08-05'),
(7, 3, 'RENT', 'VILLA', 'asdfgh', 'villa', 3, '2019-08-05');
CREATE TABLE `villa` (
`id` int(11) NOT NULL,
`main_heading` varchar(256) NOT NULL,
`sub_heading` text NOT NULL,
`build_up_area` int(11) NOT NULL,
`carpet_area` int(11) NOT NULL,
`no_of_bedrooms` int(11) NOT NULL,
`bathrooms` int(11) NOT NULL,
`available_from` date NOT NULL,
`furnishing` varchar(256) NOT NULL,
`facing` varchar(100) NOT NULL,
`flooring` varchar(256) NOT NULL,
`total_area` varchar(256) NOT NULL,
`width_of_facing_road` varchar(100) NOT NULL,
`property_age` int(11) NOT NULL,
`property_price` decimal(16,2) NOT NULL DEFAULT '0.00',
`address` text NOT NULL,
`about_property` text NOT NULL,
`location` varchar(256) NOT NULL,
`amenities` text NOT NULL,
`owner_name` varchar(256) NOT NULL,
`owner_email` varchar(256) NOT NULL,
`owner_phone` varchar(100) NOT NULL,
`active` enum('Y','N') NOT NULL DEFAULT 'Y'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
INSERT INTO `villa` (`id`, `main_heading`, `sub_heading`, `build_up_area`, `carpet_area`, `no_of_bedrooms`, `bathrooms`, `available_from`, `furnishing`, `facing`, `flooring`, `total_area`, `width_of_facing_road`, `property_age`, `property_price`, `address`, `about_property`, `location`, `amenities`, `owner_name`, `owner_email`, `owner_phone`, `active`) VALUES
(2, 'My Villa', 'Kakkanad', 54, 5, 4, 4, '2019-08-06', 'semi', 'west', 'not-vitrified', '111', '10', 0, '12.00', 'fhgfgh', 'ghfghf', 'Kochi', 'car_parking,water_supply,garden,fitness_center,shower,fridge', 'dfdfdf', 'abc#edg.com', '9876543210', 'Y'),
(3, 'My Villa 2', 'Place', 54, 5, 4, 4, '2019-08-06', 'semi', 'west', 'not-vitrified', '111', '10', 0, '12.00', 'fhgfgh', 'ghfghf', 'Kochi', 'car_parking,water_supply,garden,fitness_center,shower,fridge', 'dfdfdf', 'abc#edg.com', '9876543210', 'Y');
ALTER TABLE `apartment`
ADD PRIMARY KEY (`id`);
ALTER TABLE `land`
ADD PRIMARY KEY (`id`);
ALTER TABLE `property`
ADD PRIMARY KEY (`property_id`),
ADD KEY `ref_id` (`ref_id`);
ALTER TABLE `villa`
ADD PRIMARY KEY (`id`);
ALTER TABLE `apartment`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
ALTER TABLE `land`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `property`
MODIFY `property_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
ALTER TABLE `villa`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
I expect result based on the decreasing of post date irrespective of the order of the table I provided.
As we know only one of the type can be mapped with the property.
So data will be generated from one table(which store details of that property type) only, other tables will produce null.
A great way to pick data from multiple columns if only one of them is not null, is using CONCAT_WS or COALESCE.
SELECT
P.property_id, P.property_url,
CONCAT_WS('', V.main_heading, A.main_heading, L.main_heading) AS main_heading,
CONCAT_WS('', V.sub_heading, A.sub_heading, L.sub_heading) AS sub_heading,
CONCAT_WS('', V.location, A.location, L.location) AS location,
CONCAT_WS('', V.about_property, A.about_property, L.about_property) AS about_property,
CONCAT_WS('', V.property_price, A.property_price, L.property_price) AS property_price,
CONCAT_WS('', V.available_from, A.available_from, L.available_from) AS available_from,
P.posted_on
FROM property P
LEFT JOIN villa V ON P.ref_table = 'villa' AND P.ref_id = V.id
LEFT JOIN apartment A ON P.ref_table = 'apartment' AND P.ref_id = A.id
LEFT JOIN land L ON P.ref_table = 'land' AND P.ref_id = L.id
ORDER BY P.posted_on DESC;
Using COALESCE at place of CONCAT_WS would be like:
COALESCE(V.main_heading, A.main_heading, L.main_heading) AS main_heading
Reference: MySQL Function: COALESCE, MySQL Function: CONCAT_WS
You can integrate the following query in CI instead of looping in php. It provides single set array.
SELECT
a.*,
b.id,
c.id,
d.id
FROM
`property` AS a
LEFT JOIN `apartment` AS b
ON a.`ref_id` = b.id
AND a.`ref_table` = 'apartment'
LEFT JOIN `land` AS c
ON a.`ref_id` = c.id
AND a.`ref_table` = 'land'
LEFT JOIN `villa` AS d
ON a.`ref_id` = d.id
AND a.`ref_table` = 'villa'
ORDER BY a.`posted_by` DESC ;
Here, joining tables respective of constant table name and other fields will return null.Those conditions can map in PHP code.
Note : add necessary columns in select what you needed.
add this condition too : $this->db->where('p.posted_by', $this->session->user_id); in query

#1054-Unknown column 'userid' in 'field list' in mysql. Getting error when i am importing a file containing this table in mysql through xampp

CREATE TABLE IF NOT EXISTS `user` (
`userid` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL DEFAULT '',
`password` varchar(100) NOT NULL DEFAULT '',
`authtype` varchar(20) NOT NULL DEFAULT 'mysql',
`disabled` int(1) NOT NULL DEFAULT '0',
`logonchange` int(1) NOT NULL DEFAULT '0',
`expiry` tinyint(1) NOT NULL DEFAULT '0',
`ldapdn` varchar(250) DEFAULT NULL,
`cookieid` varchar(32) DEFAULT NULL,
`lastchanged` int(11) DEFAULT '0',
`first_name` varchar(250) DEFAULT NULL,
`last_name` varchar(250) DEFAULT NULL,
`email` varchar(250) DEFAULT NULL,
`payroll_number` varchar(50) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2234 ;
INSERT INTO `user` (`userid`, `username`, `password`, `authtype`, `disabled`, `logonchange`, `expiry`, `ldapdn`, `cookieid`, `lastchanged`, `first_name`, `last_name`, `email`, `payroll_number`) VALUES
(1, 'administrator', '200ceb26807d6bf99fd6f4f0d1ca54d4', 'mysql', 0, 0, 0, '', 'e6f33989529daf141bd1406702b995fc', 1155190068, NULL, NULL, NULL, ''),
(2224, 'staff', '1253208465b1efa876f982d8a9e73eef', 'mysql', 0, 0, 0, 'NULL', '972b26e91f1a089cb0cafb16cbeb422c', 1156372109, NULL, NULL, NULL, ''),
(2233, 'guest', '', 'mysql', 0, 0, 0, NULL, NULL, 0, NULL, NULL, NULL, '');
I know it is late. :) See AUTO_INCREMENT=2234 in your code?
It says auto increment starts with 2234 which is correct for any further entries but when importing we are inserting with userid = 1 for the first entry which breaks the rule. This is the reason why you are getting error. You can remove the auto increment part from the create table statement and use the below statement after the Insert statements
ALTER TABLE user AUTO_INCREMENT = 2234;
Errors like: #1054-Unknown column 'xxxx' in 'field list' can be solved by simple editing the import file.

Need help to correct MySQL query results from two tables

I have two tables one is events and one is periods. I want to select these two tables data in a single query. These two tables have a common field start_time and i want the results to be ordered by that column.
Table structure of the tables:
CREATE TABLE IF NOT EXISTS `events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`event_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`start_time` time NOT NULL,
`end_time` time NOT NULL,
`is_repeated` tinyint(4) NOT NULL DEFAULT '0',
`alarm_type` enum('set_date','days','monthly') COLLATE utf8_unicode_ci NOT NULL,
`event_alarm_date` date DEFAULT NULL,
`alarm_days` set('Sat','Sun','Mon','Tue','Wed','Thu','Fri') COLLATE utf8_unicode_ci DEFAULT NULL,
`monthly_alarm_days` set('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31') COLLATE utf8_unicode_ci DEFAULT NULL,
`alarm_audio` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`count_down_time` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ;
--
-- Dumping data for table `events`
--
INSERT INTO `events` (`id`, `event_name`, `start_time`, `end_time`, `is_repeated`, `alarm_type`, `event_alarm_date`, `alarm_days`, `monthly_alarm_days`, `alarm_audio`, `created_on`, `count_down_time`) VALUES
(1, 'Lunch Break', '10:30:45', '11:30:45', 1, 'days', NULL, 'Mon,Wed', NULL, '1411587500.mp3', '0000-00-00 00:00:00', 0),
(2, 'Openning Ceremony', '10:30:45', '11:30:45', 1, 'monthly', NULL, NULL, '2,3,4', '1411587568.mp3', '0000-00-00 00:00:00', 0),
(3, 'Inspection', '10:30:45', '12:45:30', 0, 'set_date', '2014-09-26', NULL, NULL, '1411587695.mp3', '0000-00-00 00:00:00', 0),
(5, 'Test2', '10:30:45', '11:30:45', 1, 'monthly', NULL, NULL, '3,4,5', '1411595801.mp3', '2014-09-24 21:56:41', 0),
(6, 'Test3', '22:20:30', '23:25:30', 1, 'days', NULL, 'Sun,Mon', NULL, '1411597086.mp3', '2014-09-24 22:18:06', 0);
CREATE TABLE IF NOT EXISTS `periods` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`period_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`start_time` time NOT NULL,
`repeat_on` set('Sat','Sun','Mon','Tue','Wed','Thu','Fri') COLLATE utf8_unicode_ci DEFAULT NULL,
`count_down_time` tinyint(4) NOT NULL DEFAULT '40',
`created_on` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`period_audio` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `periods`
--
INSERT INTO `periods` (`id`, `period_name`, `start_time`, `repeat_on`, `count_down_time`, `created_on`, `period_audio`) VALUES
(1, 'Quran Recitation', '08:15:00', 'Mon,Wed', 30, '2014-09-25 01:30:26', ''),
(2, 'Morning Assembly', '08:15:00', 'Sun,Mon,Wed', 30, '2014-09-28 04:25:24', '');
I have written query below. This query gets 8 records while according to the tables data it should get 5 records.
SELECT pr.period_name,
pr.start_time as period_start_time,
pr.repeat_on, pr.created_on as period_created_on,
pr.count_down_time as period_count_down_time,
pr.period_audio, ev.event_name,
ev.start_time as event_start_time,
ev.end_time as event_end_time,
ev.is_repeated, ev.alarm_type,
ev.event_alarm_date,ev.alarm_days,
ev.monthly_alarm_days,
ev.alarm_audio,
ev.created_on as event_created_on,
ev.count_down_time as event_count_down_time
FROM periods as pr, events as ev
WHERE
FIND_IN_SET('Mon',repeat_on)>0 AND
CASE alarm_type WHEN 'set_date' THEN FIND_IN_SET('2014-09-25',event_alarm_date)>0
WHEN 'days' THEN FIND_IN_SET('Mon',alarm_days) > 0
WHEN 'monthly' THEN FIND_IN_SET('2',monthly_alarm_days) > 0
END = 1
ORDER BY pr.start_time AND ev.start_time
Any help appreciated.

passwords changing on export/import of database

I have a linux shared hosting with phpmyadmin and MySQL
I run a wamp server without any amends. MOstly it works fine.
However when I export out a database from the wamp and then export it into the Linux the passwords change and I have to go in and reset them.
What's going on please?
--
-- Table structure for table `pfd8x_users`
--
CREATE TABLE IF NOT EXISTS `pfd8x_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`username` varchar(150) NOT NULL DEFAULT '',
`email` varchar(100) NOT NULL DEFAULT '',
`password` varchar(100) NOT NULL DEFAULT '',
`block` tinyint(4) NOT NULL DEFAULT '0',
`sendEmail` tinyint(4) DEFAULT '0',
`registerDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastvisitDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`activation` varchar(100) NOT NULL DEFAULT '',
`params` text NOT NULL,
`lastResetTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date of last password reset',
`resetCount` int(11) NOT NULL DEFAULT '0' COMMENT 'Count of password resets since lastResetTime',
`otpKey` varchar(1000) NOT NULL DEFAULT '' COMMENT 'Two factor authentication encrypted keys',
`otep` varchar(1000) NOT NULL DEFAULT '' COMMENT 'One time emergency passwords',
PRIMARY KEY (`id`),
KEY `idx_name` (`name`),
KEY `idx_block` (`block`),
KEY `username` (`username`),
KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=401 ;
--
-- Dumping data for table `pfd8x_users`
--
INSERT INTO `pfd8x_users` (`id`, `name`, `username`, `email`, `password`, `block`, `sendEmail`, `registerDate`, `lastvisitDate`, `activation`, `params`, `lastResetTime`, `resetCount`, `otpKey`, `otep`) VALUES
(400, 'Super User', 'NAME', 'fred#email.com', '$P$D5YNEQ62cnGZy0cFTL/x49uBSkdWU80', 0, 1, '2014-04-01 14:59:48', '2014-05-01 16:49:46', '0', '{"admin_style":"","admin_language":"","language":"","editor":"","helpsite":"","timezone":""}', '0000-00-00 00:00:00', 0, '', '');
-- --------------------------------------------------------

Find all missing mapping table entries

I need to be able to determine all of the people that were missing from attendance in a series of meetings.
I have a solution to figure this problem out with JS on the client's computer but I think it could be done more efficiently on the server.
Table A (people) -> Table B (attendance) <- Table C(meeting)
The attendance is a mapping table of items in table A and C.
See: http://sqlfiddle.com/#!8/6db81 for the exact schema
What I want is to determine all of the meetings that people have missed. That is there is no entry for that person for that meeting in the attendance table B.
Desired output should include a minimum of the lid (user id) and mid (meeting ID).
lid, firstname, lastname, mid, meeting_title, start.
The solution in JS would be to send the results of a cross of A and C, and the results of B to the client. Then remove all of the items in B from the cross of A and C.
CREATE TABLE IF NOT EXISTS `attendance` (
`mid` bigint(20) NOT NULL,
`sid` bigint(20) DEFAULT NULL,
`entered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`lid` varchar(64) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`mid`,`lid`),
KEY `entered` (`entered`)
);
INSERT INTO `attendance` (`mid`, `sid`, `entered`, `lid`) VALUES
(5, NULL, '2013-12-25 21:44:27', '100'),
(5, NULL, '2013-12-25 21:44:19', '200'),
(5, NULL, '2013-12-25 21:44:21', '300'),
(9, NULL, '2013-12-26 14:49:49', '200'),
(9, NULL, '2013-12-26 07:10:34', '300');
CREATE TABLE IF NOT EXISTS `meetings` (
`mid` bigint(11) NOT NULL AUTO_INCREMENT,
`title` varchar(32) CHARACTER SET utf8 NOT NULL,
`start` datetime NOT NULL COMMENT 'registration start time',
`stop` datetime NOT NULL COMMENT 'registration stop time',
PRIMARY KEY (`mid`),
UNIQUE KEY `title` (`title`)
);
INSERT INTO `meetings` (`mid`, `title`, `start`, `stop`) VALUES
(5, 'Meeting 1', '2013-12-25 01:12:00', '2013-12-25 23:12:00'),
(9, 'Meeting 2', '2013-12-26 01:00:00', '2013-12-26 23:00:00');
CREATE TABLE IF NOT EXISTS `people` (
`sid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`lid` varchar(64) NOT NULL,
`firstname` varchar(64) NOT NULL,
`lastname` varchar(64) NOT NULL,
`title` varchar(5) DEFAULT NULL,
`address` varchar(128) DEFAULT NULL,
`city` varchar(64) DEFAULT NULL,
`state` varchar(2) DEFAULT NULL,
`zip` varchar(9) DEFAULT NULL,
`phone` varchar(12) DEFAULT NULL,
`cell` varchar(12) DEFAULT NULL,
`email` varchar(64) DEFAULT NULL,
PRIMARY KEY (`sid`),
UNIQUE KEY `sid` (`sid`),
UNIQUE KEY `lid` (`lid`)
);
INSERT INTO `people` (`sid`, `lid`, `firstname`, `lastname`, `title`, `address`, `city`, `state`, `zip`, `phone`, `cell`, `email`) VALUES
(1, '100', 'Fred', 'Jones', 'Mr.', 'Somewhere', 'City', 'AK', '12345', '123-123-1234', '123-123-1234', 'email#email.com'),
(2, '200', 'Wilma', 'Jones', 'Mrs.', '', 'City', '', '12346', '', NULL, '');
You have to join people and meetings table to get all possible combinations of meeting id and userid and then filter out only those, which are not present in attendance table.
SELECT a.lid,
b.mid
FROM people a
CROSS JOIN meetings b
WHERE NOT EXISTS (SELECT 1
FROM attendance c
WHERE c.mid = b.mid
AND c.lid = a.lid);
Fiddle