my database schema is below, each id from email table is associated with an id from attachment table, some do not. for example id 1 from email table have attachment(s) from attachments table (3 entries of id 1 for example), while id 2 from email does not have an id2 in attachments. I tried to query the result using the following, but only attachments field showed. In essence, I want the result to show everything from date x to date y, whether it has an attachment or not.
SELECT CONCAT(email.from_fld , date_fld) AS name, email.body_fld, attachments.attach_fld
FROM email
INNER JOIN attachments
ON email.id = attachments.id
WHERE date_fld >= "2012-01-01 00:00:00" AND date_fld <= "2013-01-01 23:59:59" ORDER BY date_fld ASC;
This is my database Schema
email table
id INT
from_fld VARCHAR
to_fld VARCHAR
subj_fld MEDIUMTEXT
date_fld DATETIME
mailbox VARCHAR
mailto VARCHAR
body_fld LONGTEXT
numAttach INT
attachNames MEDIUMTEXT
attachText MEDIUMTEXT
headings MEDIUMTEXT
attachments table
id INT
type_fld VARCHAR
filename_fld VARCHAR
encode_fld INT
attach_fld LONGBLOB
origemail table
id INT
orig_fld LONGBLOB
tags table
id INT
cat_fld VARCHAR
key_fld VARCHAR
priority_fld INT
notes_fld MEDIUMTEXT
You want a left join
if you want everything in the first table in the from
clause:
SELECT CONCAT(e.from_fld , e.date_fld) AS name, e.body_fld, a.attach_fld
FROM email e LEFT JOIN
attachments a
ON e.id = a.id
WHERE e.date_fld >= '2012-01-01' AND
e.date_fld < '2013-01-02'
ORDER BY date_fld ASC;
Notice the other changes:
Try using 'full join' instead of inner join
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I have a view with the following informations:
My console shows this problem when trying to push data into my db
It has been noted that Wordpress makes 27 MySQL queries for a page load on a vanilla WordPress install on the default theme and even more as more plugins are added