Book a Demo

Author Topic: Multiple object properties SQL query issue  (Read 4562 times)

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Multiple object properties SQL query issue
« on: January 30, 2014, 12:07:27 pm »
Hi,

I have query below however am unable to execute it. It keeps returning the error/message that there is a syntax error in FROM clause. What am I missing? The model is running off an EAP project file.

Code: [Select]
SELECT * FROM t_object INNER JOIN (SELECT * FROM t_objectproperties tag WHERE tag.Property = 'Location' AND tag.Value = 'Queens') AS location ON t_object.Object_ID = location.Object_ID INNER JOIN (SELECT * FROM t_objectproperties tag WHERE tag.Property = 'Room' AND tag.Value = 'King') AS type ON t_object.Object_ID = type.Object_ID

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Multiple object properties SQL query issue
« Reply #1 on: January 30, 2014, 06:20:33 pm »
Probably because you are trying to join subqueries.
Why would you want to do that?

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Multiple object properties SQL query issue
« Reply #2 on: January 30, 2014, 08:59:28 pm »
EAP == MS Access == not really a RDBMS but some Mickeysoft lookalike. It eats only a very redundant subset of SQL.

q.

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: Multiple object properties SQL query issue
« Reply #3 on: January 31, 2014, 04:53:29 am »
Hi Geert,

I am attempting to filter a result set. For example, the first query would return all results that matched location based in Queens. The second query would return results of all rooms in Queens that were King. How else would I be able to achieve this?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Multiple object properties SQL query issue
« Reply #4 on: January 31, 2014, 05:55:54 pm »
Just use joins between tables iso joins between subqueries
In a proper DBMS this works
Code: [Select]
select * from t_object o
inner join t_objectproperties location on o.Object_ID = location.Object_ID
                              and location.Property = 'Location'
                              and location.Value = 'Queens'
inner join t_objectproperties _type on o.Object_ID = _type.Object_ID
                              and _type.Property = 'Room'
                              and _type.Value = 'King'

In MS Access you'll have to use this:
Code: [Select]
select * from ((t_object o
inner join t_objectproperties location on location.Object_ID = o.Object_ID)
inner join t_objectproperties ttype on ttype.Object_ID = o.Object_ID)
where
location.Property = 'Location'
and location.Value = 'Queens'
and ttype.Property = 'Room'
and ttype.Value = 'King'

Geert
« Last Edit: January 31, 2014, 06:03:18 pm by Geert.Bellekens »