Book a Demo

Author Topic: Strange SQL query behavior  (Read 3243 times)

Piotrek

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Strange SQL query behavior
« on: February 10, 2009, 01:14:16 am »
Hi all,

I’m using EA 7.1.827 + MySQL 5
I was trying to make a simple query that lists all requirements I have in model, and packages they are in.
Simple query looks like this:
SELECT t_package.Name, t_object.Name, t_object.Object_Type
FROM t_package LEFT JOIN t_object ON t_package.Package_ID = t_object.Package_ID
WHERE t_object.Object_Type="Requirement";

When run in EA it displays the same values for both “Name” fields. Both have values from t_object table.
I was trying to figure out, what’s going on, and I have changed order of fields in query.
SELECT t_object.Name, t_package.Name, t_object.Object_Type …. (rest stays the same)

Now the results are different. Again the same values are displayed in both “Name” fields, but this time these are values from t_package table.

Is there known solution, how to make such query work?

Regards,
Piotrek

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Strange SQL query behavior
« Reply #1 on: February 10, 2009, 08:14:35 am »
You'll need to provide an alias for one or both columns.

SELECT t_package.Name as PackageName, t_object.Name, t_object.Object_Type
FROM t_package LEFT JOIN t_object ON t_package.Package_ID = t_object.Package_ID
WHERE t_object.Object_Type="Requirement";

Piotrek

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Strange SQL query behavior
« Reply #2 on: February 10, 2009, 07:02:09 pm »
Thanks a lot! It helped. I should have thought about adding aliases.

Thank you,
Piotr