Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:14:14+00:00 2026-05-26T23:14:14+00:00

I have the following database — MYSQL DROP TABLE IF EXISTS Attributes; DROP TABLE

  • 0

I have the following database

-- MYSQL
DROP TABLE IF EXISTS Attributes;
DROP TABLE IF EXISTS LibraryHistory;
DROP TABLE IF EXISTS Library;

CREATE TABLE Library (
    iD              VARBINARY(16) NOT NULL,   -- UUID & PK
    name            NVARCHAR(500) NOT NULL,   -- Name for the entry
    contentType     NVARCHAR(50)  NOT NULL,   -- Mime type of data
    content         LONGBLOB      NOT NULL,   -- Data a for the entry
    subsectionOf    VARBINARY(16),            -- Library UUID & FK
    subsectionOrder INT,                      -- Oder of Subsections 
    lastModifiedBy  VARBINARY(16),            -- User UUID & FK
    lastModified    DATETIME      NOT NULL,   -- Last time the record was updated
    PRIMARY KEY (`iD`)
);

CREATE TABLE LibraryHistory (
    iD              VARBINARY(16) NOT NULL,   -- UUID & PK
    libraryID       VARBINARY(16) NOT NULL,   -- Library UUID & FK
    name            NVARCHAR(500) NOT NULL,   -- Name for the entry
    contentType     NVARCHAR(50)  NOT NULL,   -- Mime type of data
    content         LONGBLOB      NOT NULL,   -- Data a for the entry
    subsectionOf    VARBINARY(16),            -- Library UUID & FK
    subsectionOrder INT,                      -- Oder of Subsections 
    lastModifiedBy  VARBINARY(16),            -- User UUID & FK
    lastModified    DATETIME      NOT NULL,   -- Last time the record was updated
    PRIMARY KEY (`iD`)
);

CREATE TABLE Attributes (
    iD              VARBINARY(16) NOT NULL,  -- UUID & PK  (Potentially could be removed)
    libraryID       VARBINARY(16) NOT NULL,  -- Library UUID & FK
    name            NVARCHAR(500) NOT NULL,  -- Name of attribute
    dataType        INT           NOT NULL,  -- The type of data the attribute holds (int, date, string, etc.)
    data            NVARCHAR(500) NOT NULL,  -- Value of attribute
    lastModifiedBy  VARBINARY(16),           -- User UUID & FK
    lastModified    DATETIME      NOT NULL,  -- Last time the record was updated
    PRIMARY KEY (`iD`)
);

ALTER TABLE Library ADD CONSTRAINT FK_subsection FOREIGN KEY (subsectionOf) REFERENCES Library(iD);
-- ALTER TABLE Library ADD CONSTRAINT FK_modifier FOREIGN KEY (lastModifiedBy) REFERENCES Users(iD);
ALTER TABLE LibraryHistory ADD CONSTRAINT FK_Hist_Library FOREIGN KEY (libraryID) REFERENCES Library(iD);
ALTER TABLE Attributes ADD CONSTRAINT FK_Attr_Library FOREIGN KEY (libraryID) REFERENCES Library(iD);

-- Example Data
INSERT INTO `Library` VALUES(0x01, 'People', 'text', '', NULL, NULL, NULL, '2011-11-16 20:27:54');
INSERT INTO `Library` VALUES(0x02, 'Jane Doe', 'text', '', NULL, NULL, NULL, '2011-11-16 20:29:13');
INSERT INTO `Library` VALUES(0x03, 'Younger Years', 'text', '', 0x02, 1, NULL, '2011-11-16 00:00:00');
INSERT INTO `Library` VALUES(0x04, 'College Years', 'test', '', 0x02, 2, NULL, '2011-11-16 20:31:52');
INSERT INTO `Library` VALUES(0x05, 'Yale', 'text', '', 0x04, 2, NULL, '2011-11-16 20:32:44');
INSERT INTO `Library` VALUES(0x06, 'Community College', 'text', '', 0x04, 1, NULL, '2011-11-16 20:33:11');
INSERT INTO `Library` VALUES(0x07, 'John Doe', 'text', '', NULL, NULL, NULL, '2011-11-16 20:34:40');
INSERT INTO `Library` VALUES(0x08, 'Planets', 'text', '', NULL, NULL, NULL, '2011-11-16 20:27:54');
INSERT INTO `Library` VALUES(0x09, 'Earth', 'text', '', NULL, NULL, NULL, '2011-11-16 20:27:54');
INSERT INTO `Library` VALUES(0x10, 'Mars', 'text', '', NULL, NULL, NULL, '2011-11-16 20:27:54');

INSERT INTO `Attributes` VALUES(0x01, 0x02, 'TypeOf', 1, 0x01, NULL, '2011-11-16 20:34:40');
INSERT INTO `Attributes` VALUES(0x02, 0x02, 'BirthDate', 2, '19770521', NULL, '2011-11-16 20:34:40');
INSERT INTO `Attributes` VALUES(0x03, 0x02, 'EyeColor', 3, 'Brown', NULL, '2011-11-16 20:34:40');
INSERT INTO `Attributes` VALUES(0x04, 0x07, 'TypeOf', 1, 0x01, NULL, '2011-11-16 20:34:40');
INSERT INTO `Attributes` VALUES(0x05, 0x07, 'BirthDate', 2, '19740521', NULL, '2011-11-16 20:34:40');
INSERT INTO `Attributes` VALUES(0x06, 0x09, 'TypeOf', 1, 0x08, NULL, '2011-11-16 20:34:40');
INSERT INTO `Attributes` VALUES(0x07, 0x10, 'TypeOf', 1, 0x08, NULL, '2011-11-16 20:34:40');

So far I have my query looking like this

SELECT `Library`.*, `Attributes`.*
FROM `Library`
LEFT JOIN `Attributes` AS `category` ON `category`.`libraryID`=`Library`.`iD` AND `category`.`name`='TypeOf'
LEFT JOIN `Attributes` ON `Attributes`.`libraryID`=`Library`.`iD` AND `category`.`name`!='TypeOf'
WHERE
(`Library`.`name` = 'People' OR `category`.`data` = (SELECT iD FROM `Library` WHERE `Library`.`name` = 'People'))

I get 3 rows returned, in all 3 rows the Attributes.* fields are blank. I’m trying to get the query to return 4 rows. Two rows for Jane Doe, one for each attribute (BirthDate and EyeColor) and I’m trying to get the 1 row for John Doe to have the BirthDate attribute filled in. What do I need to do to get the attributed for each Library record selected to show?

Edit:
When I run the above query I get the following result

iD  name      contentType  content      subsectionOf  subsectionOrder lastModifiedBy  lastModified         iD    libraryID  name  dataType  data  lastModifiedBy  lastModified
01  People    text         [BLOB - 0B]  NULL          NULL            NULL            2011-11-16 20:27:54  NULL  NULL       NULL  NULL      NULL  NULL            NULL
02  Jane Doe  text         [BLOB - 0B]  NULL          NULL            NULL            2011-11-16 20:29:13  NULL  NULL       NULL  NULL      NULL  NULL            NULL
07  John Doe  text         [BLOB - 0B]  NULL          NULL            NULL            2011-11-16 20:34:40  NULL  NULL       NULL  NULL      NULL  NULL            NULL

I would like to get the follow result

iD  name      contentType  content      subsectionOf  subsectionOrder lastModifiedBy  lastModified         iD    libraryID  name       dataType  data      lastModifiedBy  lastModified
01  People    text         [BLOB - 0B]  NULL          NULL            NULL            2011-11-16 20:27:54  NULL  NULL       NULL       NULL      NULL      NULL            NULL
02  Jane Doe  text         [BLOB - 0B]  NULL          NULL            NULL            2011-11-16 20:29:13  02    02         BirthDate  2         19770521  NULL            2011-11-16 20:34:40
02  Jane Doe  text         [BLOB - 0B]  NULL          NULL            NULL            2011-11-16 20:29:13  03    02         EyeColor   3         Brown     NULL            2011-11-16 20:34:40
07  John Doe  text         [BLOB - 0B]  NULL          NULL            NULL            2011-11-16 20:34:40  05    07         BirthDate  2         19740521  NULL            2011-11-16 20:34:40
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:14:15+00:00Added an answer on May 26, 2026 at 11:14 pm

    I think the problem is in your join conditions. Specifically, you have:

    LEFT JOIN `Attributes` ON `Attributes`.`libraryID`=`Library`.`iD` AND `category`.`name`!='TypeOf'
    

    Notice that the latter part of the join conditions references category when I think it should be Attributes.

    The following query seems to produce the results you require (at least it does for me):

    SELECT `Library`.*, `Attributes`.*
    FROM `Library`
    LEFT JOIN `Attributes` AS `category` ON `category`.`libraryID`=`Library`.`iD` AND `category`.`name`='TypeOf'
    LEFT JOIN `Attributes` ON `Attributes`.`libraryID`=`Library`.`iD` AND `Attributes`.`name`!='TypeOf'
    WHERE
    (`Library`.`name` = 'People' OR `category`.`data` = (SELECT iD FROM `Library` WHERE `Library`.`name` = 'People'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following database: CREATE TABLE ContentNodes ( Id UNIQUEIDENTIFIER NOT NULL, Revision
I have the following database structure: CREATE TABLE `author` ( `id` int(10) unsigned NOT
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have the following database: CREATE TABLE QUESTION ( QUES_ID INTEGER AUTO INCREMENT, TOPIC_ID
Assuming you have the following database table: create table Names ( Id INT IDENTITY
i have a database table prop_amenities which have following columns here is the create
I have the following database structure: CREATE TABLE LookupTable ( PK UNIQUEIDENTIFIER PRIMARY KEY,
Let's say I have the following database table: record_id | record_date | record_value -----------+-------------+--------------
I have the following table relationship in my database: Parent / \ Child1 Child2
I have the following tables in a database (i'll only list the important attributes):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.