mysql - Query returning related assets -


I have 2 tables, an asset table that holds digital assets (examples of articles, pictures, etc.) The second table is an asset_link table that shows the relationships of 1-1 between the assets contained in the asset table. Here are the definitions of the table:

  create table 'property' (`id` int (11) not NULL AUTO_INCREMENT,` source` varchar (255) default zero, `Title` varchar (255) default zero,` date_created` datetime default zero, `date_embargo` datetime default zero,` date_expires` datetime default zero, `date_updated` datetime default zero,` keywords` varchar (255) default zero, `status Negative integer (11) default zero, `priority` integer (11) default zero,` fk_site` integer (11) default zero, `resource_type` varchar (255) default zero,` resou Rce_id` integer (11) default zero, `fk_user` integer (11) default zero, primary key (` id`)) engine = InnoDB; Create table `asset_links` (` id` integer (11) not NULL AUTO_INCREMENT, `asset_id1` integer (11) default zero,` asset_id2` integer (11) default zero, primary key (`id`)) engine = InnoDB; The following rows are in the asset_links table:, enter  
  `check Asset_links` (asset_id1, asset_id2) value (1,3) (1, 4) , (2,10), (2,56);  

I am looking to write a query that will return all the assets that will satisfy any property search criteria and all of the property linked to that property within the same query Will return the associated asset data.

e.g. Asset 3 attributes

  • Asset 4 attributes
  • Asset 1 attributes

    • Asset 2 attributes

      • Asset 10 attributes
      • Asset 56 Attributes

    What is the best way to write a query?

  •  select  a1 *, A2. * From Asset A1 Left External JOIN (Join Asset_Links L but at l.asset_id2 = a2.id Asset A2) (a1.id = l.asset_id1) where in a1.id (1, 2) and ... whatever The circumstances you want ...  

    I leave the placeholder text for my "any search criteria" because this is not a real question.


    Give your comment: You can not find the results you are describing from a relational database in a query, in a SQL query result should be the same column on each row, and in each row There are values ​​for the column. What you describe in a single SQL query, you can not do this.

    If you want to set results with super-rows and sub-rows, then you have to use a non-relational database. Try CouchDB or MongoDB.


    Comments

    Popular posts from this blog

    windows - Heroku throws SQLITE3 Read only exception -

    lex - Building a lexical Analyzer in Java -

    python - rename keys in a dictionary -