ambiguous error in mysql recordset in Dreamweaver - mysql

The following recordset in Dreamweaver throws a 1052 ambiguous error every time I attempt to test it. I know it has something to do with the dateADDED, but don't know how to fix it.
SELECT commentID, commentTitle, commentContent, topicTable.topicTitle, DAYNAME(dateADDED) as day, MONTHNAME(dateADDED) as month,
DAY(dateADDED) as date, YEAR(dateADDED) as year
FROM commentTable, topicTable
WHERE commentID = colname AND topicTable.topidID = commentTable.topicID
Here is the layout of the tables,
CREATE TABLE userTable
(
userID VARCHAR(15) NOT NULL,
screenName VARCHAR(15) NOT NULL UNIQUE,
userPasswd CHAR(40) NOT NULL,
firstName VARCHAR(15) NOT NULL,
lastName VARCHAR(25) NOT NULL,
dateJoined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
lastlogin DATETIME,
PRIMARY KEY(userID)
)
;
CREATE TABLE categoryTable
(
categoryID MEDIUMINT AUTO_INCREMENT NOT NULL,
categoryName VARCHAR(30) NOT NULL,
categoryDescription VARCHAR(200) NOT NULL,
PRIMARY KEY (categoryID)
)
;
CREATE TABLE topicTable
(
topicID MEDIUMINT AUTO_INCREMENT NOT NULL,
topicTitle VARCHAR(30) NOT NULL,
userID VARCHAR(15) NOT NULL,
dateAdded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
categoryID MEDIUMINT NOT NULL,
PRIMARY KEY (topicID)
)
;
CREATE TABLE commentTable
(
commentID MEDIUMINT AUTO_INCREMENT NOT NULL,
commentTitle VARCHAR(30) NOT NULL,
commentContent TEXT NOT NULL,
userID VARCHAR(15) NOT NULL,
dateAdded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
topicID INT NOT NULL,
PRIMARY KEY (commentID)
)
;

dateADDED is represented in both tables, so you should choose from which one you want it to be in the result set :
SELECT ct.commentID
, ct.commentTitle
, ct.commentContent
, tt.topicTitle
, DAYNAME(ct.dateADDED) as `day`
, MONTHNAME(ct.dateADDED) as `month`
, DAY(ct.dateADDED) as `date`
, YEAR(ct.dateADDED) as `year`
FROM commentTable ct
JOIN topicTable tt ON ct.commentID = tt.colname AND tt.topidID = ct.topicID
By the way, still wonder, what colname stands for, maybe it should be ct.userID = tt.userID instead?

Related

How to get users by last message in Laravel Eloquent

I'm currently developing a simple chat application with Laravel 8 and VueJS. I need to order users by their latest message and get the last message along with the user. Below are the tables I am using if anyone has an idea for this operation. If it's an Eloquent method, it would be better.
Users Table
create table users
(
id bigint unsigned auto_increment
primary key,
name varchar(255) not null,
email varchar(255) not null,
email_verified_at timestamp null,
password varchar(255) not null,
two_factor_secret text null,
two_factor_recovery_codes text null,
remember_token varchar(100) null,
status varchar(255) default 'online' not null,
last_seen timestamp null,
current_team_id bigint unsigned null,
profile_photo_path varchar(2048) null,
created_at timestamp null,
updated_at timestamp null,
constraint users_email_unique
unique (email)
)
collate = utf8mb4_unicode_ci;
Private Messages Table
create table private_messages
(
id bigint unsigned auto_increment
primary key,
sender_id bigint unsigned not null,
receiver_id bigint unsigned not null,
message varchar(1000) not null,
delete_type varchar(15) null,
created_at timestamp null,
updated_at timestamp null,
deleted_at timestamp null,
constraint private_messages_receiver_id_foreign
foreign key (receiver_id) references users (id)
on delete cascade,
constraint private_messages_sender_id_foreign
foreign key (sender_id) references users (id)
on delete cascade
)
collate = utf8mb4_unicode_ci;
in user model create relation function
public function privateMessages()
{
return $this->hasMany(PrivateMessage::class)->orderBy('id','DESC');
}
then use
$users = User::with('privateMessages')->all();
in this result , messages sort by id desc.

MySQL - Slow query

Sorry for the long post, but the tables involved are quite big.
When I run the query bellow it normally takes about 1m to run. However, when I remove the correlated sub-query I get the query down to 15 seconds. So I think that's the actual problem.
Problem is, I don't really know how to get the SUM results without the correlated query.
QUERY I'm trying to run
SELECT cl_clients.vat as association_vat, cl_clients.name as association_name, cl_clients_with_regions.city_id, cl_clients_with_regions.nut_1, cl_clients_with_regions.nut_2, cl_clients_with_regions.nut_3,
company.vat as company_vat, company.name, company.section, company.division, company.cae,
SUM((
SELECT SUM((COALESCE((cl_finances.sales_community_market), 0) + COALESCE((cl_finances.sales_extra_market), 0)))
from cl_finances
where cl_finances.vat = company.vat
and cl_finances.year = 2018
)) as total_sum
FROM `cl_clients_with_regions`
JOIN `cl_client_intervention_areas` ON `cl_client_intervention_areas`.`city_id` = `cl_clients_with_regions`.`city_id`
JOIN `cl_clients` ON `cl_clients`.`vat` = `cl_client_intervention_areas`.`client_vat`
INNER JOIN cl_clients_with_regions company ON cl_clients_with_regions.vat = company.vat
WHERE `cl_clients_with_regions`.`encrypted_vat` IS NOT NULL
AND `cl_clients_with_regions`.`country` IS NOT NULL
AND `cl_clients_with_regions`.`cae` IS NOT NULL
AND `cl_clients_with_regions`.`cae` != ''
AND `cl_clients_with_regions`.`division` IS NOT NULL
AND `cl_clients_with_regions`.`section` = 'A'
AND `cl_clients_with_regions`.`nut_2` = 'Centro'
GROUP BY association_vat;
CL Clients create table syntax
create table cl_clients
(
vat varchar(20) default '' not null,
encrypted_vat varchar(32) null,
temporary_vat enum ('0', '1', '') default '0' null,
sig_id int null,
phc_id int null,
client_manager int null,
name varchar(300) null,
brand varchar(255) null,
`group` varchar(200) null,
class_internacional varchar(45) null,
logoimage varchar(400) null,
social_capital varchar(100) null,
address varchar(300) null,
gps varchar(25) null,
parish varchar(70) null,
zip_code varchar(10) null,
city int null,
district int null,
country int default 75 not null,
headquarter int null,
person_title varchar(7) null,
person_contact varchar(350) null,
person_phone varchar(20) null,
person_cell varchar(15) null,
person_email varchar(150) null,
person_function varchar(150) null,
language varchar(10) null,
phone varchar(20) null,
mobile_phone varchar(20) null,
fax varchar(20) null,
email varchar(50) null,
email_alternative varchar(50) null,
website varchar(300) null,
pme varchar(500) null,
pme_lider varchar(500) null,
cae varchar(15) null,
cae_2 varchar(15) null,
certified enum ('1', '0', '') null,
sector varchar(350) null,
workers int null,
foundation_date date null,
size enum ('Micro Empresa', 'Pequena empresa', 'Média empresa', 'Grande empresa', 'Não aplicável', 'PME', '') default '' null,
company_type varchar(455) default 'Empresa' null,
type enum ('novo', 'antigo', 'analizar', '') default 'analizar' null,
entity enum ('client', 'prospect', 'suplier', 'potential', '') default 'prospect' null,
client_to_country int null,
partner enum ('1', '0', '') default '0' not null,
partner_dp enum ('0', '1', '') default '0' null,
lucrative enum ('1', '0', '') default '1' not null,
dun varchar(100) null,
debt enum ('50k', '100k', '500k', '1m', '5m', '+5m', '') null,
bankruptcy enum ('1', '0', '') default '0' null,
competitors enum ('1', '0', '') default '0' null,
dun_date date null,
bank_1 varchar(30) null,
bank_2 varchar(30) null,
bank_3 varchar(30) null,
status enum ('0', '1', '') default '1' null,
followup enum ('0', '1', '') default '1' null,
classification enum ('Prestige', 'Premium', 'Current', '') default 'Current' null,
associated enum ('0', '1', '') default '0' null,
industry_id int null,
valid enum ('0', '1', '') default '1' null,
imported_at timestamp null,
modified_by int default 0 null,
responsible_id int null,
partner_type int null,
iberinform_id int null,
iberinform_date timestamp null,
legal_form text null,
going_concern text null,
score int null,
sector_score int null,
tax_status text null,
irc_debtors_ledger enum ('0', '1') null,
ss_debtors_ledger enum ('0', '1') null,
association_class_id int null,
nature enum ('business', 'commercial', 'sectorial', 'other') null,
geographic_scope enum ('national', 'regional', 'local') null,
intervention_nut enum ('nut_1', 'nut_2', 'nut_3') null,
ch_is_associated enum ('0', '1') null,
bi enum ('0', '1') default '0' null,
updated_at timestamp null,
constraint encrypted_vat_UNIQUE
unique (encrypted_vat),
constraint vat
unique (vat),
constraint cl_clients_cl_caes_cae_fk
foreign key (cae) references cl_caes (cae)
on update cascade,
constraint clients_industry_id_fk
foreign key (industry_id) references cl_industries (id),
constraint cltns_asso_clss_id_fk
foreign key (association_class_id) references cl_association_classifications (id)
on update cascade on delete set null,
constraint country_fk_id
foreign key (country) references cl_countries (id)
on update cascade on delete cascade
);
create index cl_client_name_idx
on cl_clients (name);
create index cl_clients_bi_idx
on cl_clients (bi);
create index cl_clients_brand_idx
on cl_clients (brand);
create index cl_clients_company_type_idx
on cl_clients (company_type);
create index cl_clients_geo_index
on cl_clients (city, district);
create index cl_clients_geographic_scope_idx
on cl_clients (geographic_scope);
create index cl_clients_group_idx
on cl_clients (`group`);
create index cl_clients_nature_idx
on cl_clients (nature);
create index cltns_asso_clss_id_fk_idx
on cl_clients (association_class_id);
create index country_idx
on cl_clients (country);
create index fk_clients_industries1_idx
on cl_clients (industry_id);
alter table cl_clients
add primary key (vat);
VIEW being used in the query
create view cl_clients_with_regions as
select `grupoch`.`cl_clients`.`vat` AS `vat`,
`grupoch`.`cl_clients`.`encrypted_vat` AS `encrypted_vat`,
`grupoch`.`cl_clients`.`name` AS `name`,
`grupoch`.`cl_clients`.`brand` AS `brand`,
`grupoch`.`cl_clients`.`country` AS `country`,
`grupoch`.`cl_clients`.`district` AS `district`,
`grupoch`.`cl_clients`.`city` AS `city`,
`grupoch`.`cl_cities`.`id` AS `city_id`,
`grupoch`.`cl_cities`.`name` AS `city_name`,
`grupoch`.`cl_cities`.`nut_1` AS `nut_1`,
`grupoch`.`cl_cities`.`nut_2` AS `nut_2`,
`grupoch`.`cl_cities`.`nut_3` AS `nut_3`,
`grupoch`.`cl_clients`.`cae` AS `cae`,
`grupoch`.`cl_caes`.`description` AS `cae_designation`,
`grupoch`.`cl_caes_divisions`.`division` AS `division`,
`grupoch`.`cl_caes_divisions`.`division_designation` AS `division_designation`,
`grupoch`.`cl_caes_divisions`.`section` AS `section`,
`grupoch`.`cl_caes_divisions`.`section_designation` AS `section_designation`
from (((`grupoch`.`cl_clients` join `grupoch`.`cl_cities` on ((
(`grupoch`.`cl_clients`.`city` = `grupoch`.`cl_cities`.`city_cod`) and (`grupoch`.`cl_clients`.`district` =
`grupoch`.`cl_cities`.`district_id`)))) join `grupoch`.`cl_caes` on ((`grupoch`.`cl_caes`.`cae` = `grupoch`.`cl_clients`.`cae`)))
join `grupoch`.`cl_caes_divisions`
on ((`grupoch`.`cl_caes_divisions`.`division` = `grupoch`.`cl_caes`.`division_id`)))
where ((`grupoch`.`cl_clients`.`country` in (75, 185, 186)) and (`grupoch`.`cl_clients`.`vat` is not null));
CL finances create table syntax
create table cl_finances
(
vat varchar(20) not null,
year int not null,
workers int null,
sells varchar(300) null,
sells_variation varchar(300) null,
international_sells varchar(300) null,
international_sells_variation varchar(300) null,
liquid_results varchar(300) null,
liquid_results_variation varchar(300) null,
capital varchar(300) null,
active_liquid varchar(300) null,
financial_autonomy varchar(300) null,
modified_by int default 0 null,
sales_profitability decimal(13, 2) null,
return_on_capital decimal(13, 2) null,
sales_community_market decimal(13, 2) null,
sales_extra_market decimal(13, 2) null,
created_at timestamp null,
updated_at timestamp null,
primary key (vat, year),
constraint clients_finances_vat
foreign key (vat) references cl_clients (vat)
on update cascade on delete cascade
);
create index cl_finances_year_idx
on cl_finances (year);
create index vat
on cl_finances (vat);
## Create table syntax for cl_client_intervention_areas
create table cl_client_intervention_areas
(
client_vat varchar(20) not null,
city_id int not null,
constraint fk_cl_client_intervention_areas_cl_cities1
foreign key (city_id) references cl_cities (id)
on update cascade on delete cascade,
constraint fk_cl_client_intervention_areas_cl_clients1
foreign key (client_vat) references cl_clients (vat)
on update cascade on delete cascade
);
create index fk_cl_client_intervention_areas_cl_cities1_idx
on cl_client_intervention_areas (city_id);
create index fk_cl_client_intervention_areas_cl_clients1_idx
on cl_client_intervention_areas (client_vat);
The explain result from this query is quite big
I believe the subquery is being executed once per row in the group by clause.
Could you try the following if it makes it any better.
Change i have done is to perform the correlated query as a inline-view and then join with the main table/view -- company.vat
SELECT cl_clients.vat as association_vat, cl_clients.name as association_name, cl_clients_with_regions.city_id, cl_clients_with_regions.nut_1, cl_clients_with_regions.nut_2, cl_clients_with_regions.nut_3,
company.vat as company_vat, company.name, company.section, company.division, company.cae,
SUM(temp_val.sum_val) as total_sum
FROM `cl_clients_with_regions`
JOIN `cl_client_intervention_areas` ON `cl_client_intervention_areas`.`city_id` = `cl_clients_with_regions`.`city_id`
JOIN `cl_clients` ON `cl_clients`.`vat` = `cl_client_intervention_areas`.`client_vat`
INNER JOIN cl_clients_with_regions company ON cl_clients_with_regions.vat = company.vat
LEFT JOIN (SELECT cl_finances.vat
,SUM((COALESCE((cl_finances.sales_community_market), 0) + COALESCE((cl_finances.sales_extra_market), 0))) as sum_val
FROM cl_finances
WHERE 1=1
AND cl_finances.year = 2018
GROUP BY cl_finances.vat
)temp_val
ON company.vat=temp_val.vat
WHERE `cl_clients_with_regions`.`encrypted_vat` IS NOT NULL
AND `cl_clients_with_regions`.`country` IS NOT NULL
AND `cl_clients_with_regions`.`cae` IS NOT NULL
AND `cl_clients_with_regions`.`cae` != ''
AND `cl_clients_with_regions`.`division` IS NOT NULL
AND `cl_clients_with_regions`.`section` = 'A'
AND `cl_clients_with_regions`.`nut_2` = 'Centro'
GROUP BY association_vat;
To further explain the above answer:
Subqueries should never be in the select clause because they execute once per record that is returned / or calculated to return. This causes the query to get slower and slower as the database gets larger.
Instead, the subquery should be in the FROM clause, and the result of the subquery should be joined to and selected.

I want two tables calculate

I want to add and calculate using data from 2 tables.
The results I want are as follows.
However, if I send a query as follows:
SELECT COUNT(IF(treatment_fees_check_division = 'test',
treatment_fees_check_division, NULL)) AS COUNT, SUM(CASE WHEN
treatment_fees_check_division = 'test' THEN treatment_fees_difference
END) + SUM(advenced_amount) AS if_treatment_fees_check_division,
SUM(advenced_amount) AS sum_init_amount FROM ( SELECT
treatment_fees_check_division, treatment_fees_difference,
advenced_amount FROM hospital_payment_data, advenced_payment WHERE
hospital_payment_data.id = advenced_payment.chart_num ) AS a
These results occur.
create table of hospital_payment_data and data
CREATE TABLE `hospital_payment_data` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
`chart_num` INT(11) NOT NULL ,
`chart_name` VARCHAR(50) NOT NULL,
`visit` DATE NOT NULL,
`non_payment_sales` VARCHAR(50) NOT NULL,
`total_medical_bills` VARCHAR(50) NOT NULL,
`total_amount` VARCHAR(50) NOT NULL,
`amount_asked` VARCHAR(50) NOT NULL,
`medical_bills_payment` VARCHAR(50) NOT NULL,
`personal_liability_amount` VARCHAR(50) NOT NULL,
`non_payment` VARCHAR(50) NOT NULL,
`insurance_division` VARCHAR(50) NOT NULL,
`division` VARCHAR(50) NOT NULL,
`cash_amount_received` VARCHAR(50) NOT NULL,
`cash_receipt` VARCHAR(50) NOT NULL,
`cash_receipt_non_payment` VARCHAR(50) NOT NULL,
`cash_receipt_payment` VARCHAR(50) NOT NULL,
`card_amount_received` VARCHAR(50) NOT NULL,
`card_non_payment` VARCHAR(50) NOT NULL,
`card_payment` VARCHAR(50) NOT NULL,
`medical_bills_check` VARCHAR(50) NOT NULL,
`medical_bills_check_modify` VARCHAR(50) NOT NULL DEFAULT 'N',
`treatment_fees_difference` VARCHAR(50) NOT NULL,
`init_amount` VARCHAR(50) NOT NULL DEFAULT '0',
`treatment_fees_check_division` VARCHAR(50) NOT NULL DEFAULT '-',
`treatment_fees_check` VARCHAR(50) NOT NULL,
`treatment_fees_check_modify` VARCHAR(50) NOT NULL DEFAULT 'N',
`treatment_fees_check_memo` VARCHAR(50) NOT NULL,
PRIMARY KEY (`id`)
)
COLLATE='euckr_korean_ci'
ENGINE=InnoDB
AUTO_INCREMENT=18
;
create table of advenced_payment and data
CREATE TABLE `advenced_payment` (`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` TIMESTAMP NULL DEFAULT NULL,
`chart_num` VARCHAR(50) NULL DEFAULT NULL,
`chart_name` VARCHAR(50) NULL DEFAULT NULL,
`advenced_amount` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `chart_num` (`chart_num`)) COLLATE='euckr_korean_ci' ENGINE=InnoDB AUTO_INCREMENT=2 ;
How do fix my query??
You have numerous issues with you query. This won't fix your problems, but I recommend writing it as:
SELECT SUM(hpd.treatment_fees_check_division = 'test') AS COUNT,
(SUM(CASE WHEN hpd.treatment_fees_check_division = 'test' THEN hpd.treatment_fees_difference END) +
SUM(advenced_amount)
) AS if_treatment_fees_check_division,
SUM(advenced_amount) AS sum_init_amount
FROM hospital_payment_data hpd JOIN
advanced_payment ap
ON hpd.id = ap.chart_num;
This simplifies and fixes some issues:
The JOIN uses proper, explicit, standard, readable syntax. Never use commas in the FROM clause.
The subquery is utterly unnecessary and probably adversely affects performance.
All tables have table aliases.
All column references are qualified.
The condition count is much simplified using sum(<boolean>).
I note that treatment_fees_difference is a string, yet you are using SUM(). That is really, really bad.
In any case, your problem, is that one of the tables has multiple rows. It is hard to know which one but my guess is advanced_payment. The solution is to preaggregate before the JOIN:
SELECT SUM(hpd.treatment_fees_check_division = 'test') AS COUNT,
(SUM(CASE WHEN hpd.treatment_fees_check_division = 'test' THEN hpd.treatment_fees_difference END) +
SUM(ap.sum_init_amount)
) AS if_treatment_fees_check_division,
SUM(ap.sum_init_amount) AS sum_init_amount
FROM hospital_payment_data hpd JOIN
(SELECT ap.chart_num, COUNT(*) as cnt, SUM(advenced_amount) as sum_init_amount
FROM advanced_payment ap
GROUP BY ap.chart_num
) ap
ON hpd.id = ap.chart_num;

What seems to be the problem? Sorry im new with this

Im just testing things out but my first code didnt work.
CREATE TABLE `Accounts`.`Registry` ( `Username` VARCHAR(16) NOT NULL ,
`Password` VARCHAR(16) NOT NULL ,
`First Name` INT(20) NOT NULL ,
`Last Name` INT(20) NOT NULL ,
`Gender` INT(1) NOT NULL ,
`ID` INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`Password`, `First Name`, `Last Name`),
UNIQUE (`ID`(1000)),
UNIQUE (`Username`)) ENGINE = MyISAM;
Error
#089 - Incorrect prefix key, the used length is longer than the key part, or the storage engine doesnt support unique prefix keys
This must be the reason for the error UNIQUE (ID(1000))
Try this.
CREATE TABLE Accounts.Registry (
Username VARCHAR(16) NOT NULL ,
Password VARCHAR(16) NOT NULL ,
First Name INT(20) NOT NULL ,
Last Name INT(20) NOT NULL ,
Gender INT(1) NOT NULL ,
ID INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (Password, First Name, Last Name),
UNIQUE (ID),
UNIQUE (Username)) ENGINE = MyISAM;
As already mentioned in comment and by others remove UNIQUE (`ID` (1000)).
For better performance, create a table asInnodb and other useful info shared below
Int stores values as numbers with a range from -2147483648 to 2147483647.
First Name & Last Name change as VARCHAR(20).
Gender you can change as TINYINT.
CREATE TABLE `Accounts`.`Registry` (
`ID` INT NOT NULL AUTO_INCREMENT,
`Username` VARCHAR(16) NOT NULL,
`Password` VARCHAR(16) NOT NULL,
`First Name` INT(20) NOT NULL,
`Last Name` INT(20) NOT NULL,
`Gender` TINYINT(1) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE (`Username`)
) ENGINE=Innodb;

Optimize query for yii2

this query is getting the right data i want, but this is so slow and heavy on our server, with only 5417 rows of data. how would i optimize this query in query builder or yii2 framework way?
SELECT t1.id
FROM tbl_ticket t1
WHERE NOT EXISTS
( SELECT 1
FROM tbl_ticket
WHERE parent_id = t1.id
)
AND parent_id =0
UNION ALL
SELECT MAX( id )
FROM tbl_ticket
WHERE parent_id <>0
GROUP BY parent_id
ORDER BY id ASC
( SELECT t1.id
FROM tbl_ticket t1
LEFT JOIN tbl_ticket t2 ON t2.parent_id = t1.id
WHERE t2.id IS NULL
AND t1.parent_id = 0 )
UNION ALL
( SELECT MAX( id )
FROM tbl_ticket
WHERE parent_id <> 0
GROUP BY parent_id )
ORDER BY id ASC
The first SELECT seems to be finding ids that have no children and no parents. Correct?
The second SELECT seems to be finding the last sibling in each family, excluding Adam and Eve. Is that what you intended?
I added parentheses to move the ORDER BY away from the second SELECT to the entire query. Is that what you intended?
To make that query run 'fast', you need
INDEX(parent_id, id)
I assume, you already have PRIMARY KEY(id). (Please provide SHOW CREATE TABLE tbl_ticket.)
here is the table:
CREATE TABLE IF NOT EXISTS tbl_ticket (
id int(9) NOT NULL AUTO_INCREMENT,
parent_id int(11) NOT NULL,
ticket_title varchar(250) NOT NULL,
location_id varchar(250) CHARACTER SET latin1 NOT NULL,
status int(11) NOT NULL,
remarks varchar(250) CHARACTER SET latin1 NOT NULL,
r_date datetime NOT NULL,
d_date datetime NOT NULL,
hd_user_username varchar(250) CHARACTER SET latin1 NOT NULL,
hd_user_email varchar(250) CHARACTER SET latin1 NOT NULL,
description varchar(3000) NOT NULL,
attachment varchar(250) NOT NULL,
created_by varchar(250) NOT NULL,
updated_by varchar(250) NOT NULL,
room_no varchar(250) NOT NULL,
gsm varchar(250) NOT NULL,
file_mime_type varchar(250) NOT NULL,
file_original_name varchar(250) DEFAULT NULL,
file_size varchar(250) DEFAULT NULL,
file_extension varchar(250) DEFAULT NULL,
acknowledged varchar(250) DEFAULT NULL,
ip_address varchar(20) DEFAULT NULL,
hostname varchar(255) DEFAULT NULL,
useragent text,
closing_remark varchar(2048) DEFAULT NULL,
rating int(6) DEFAULT NULL,
is_student int(2) DEFAULT NULL,
installation int(1) DEFAULT NULL,
type int(1) DEFAULT NULL,
PRIMARY KEY (id),
KEY id (id),
KEY parent_id (parent_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5428 ;