SQL Join Two Queries Without Unique Relation -


i have tables setup , linked in system so:

products

  • actualid pk
  • productid
  • itemid

items

  • itemid pk
  • dataid

itemsdataone

  • dataid pk
  • value (value need)

itemsdatatwo

  • dataid pk
  • value (value need)

i'm having problem following select there productids more 1 instance of themselves:

select names.productid, names.name, descriptions.desc      (select products.productid, itemsdataone.value name     products     inner join items on items.itemi = product.itemid     inner join itemsdataone on itemsdataone.dataid = items.dataid) names inner join     (select products.productid, itemsdatatwo.value desc     products     inner join items on items.itemi = product.itemid     inner join itemsdatatwo on itemsdatatwo.dataid = items.dataid) descriptions on names.productid = descriptions.productid 

which returns duplicates this:

actual result

productid    name    description 01           "one"   "description one" 01           "two"   "description one" 01           "one"   "description two" 01           "two"   "description two" 

what want

productid    name    description 01           "one"   "description one" 01           "two"   "description two" 

it can done more without subselects:

select products.productid, itemsdataone.value, itemsdatatwo.value products inner join items on items.itemid = product.itemid inner join itemsdataone on itemsdataone.dataid = items.dataid inner join itemsdatatwo on itemsdatatwo.dataid = items.dataid 

(you missing relation between itemsdataone , itemsdatatwo - need have same dataid.)


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -