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 9179031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:41:43+00:00 2026-06-17T17:41:43+00:00

I have an attribute-value table av that looks like this: | attribute | value

  • 0

I have an attribute-value table av that looks like this:

| attribute | value |
~~~~~~~~~~~~~~~~~~~~~
| a1        | A1    |
| b1        | BB1   |
| b2        | BB2   |

For simplicity, assume varchar(255) on both attribute and value columns, unique index on attribute.

I need to use the values of specific attributes in a query, which looks like this:

SELECT *
FROM   t1
      ,t2
WHERE  t1.a1 = "A1"  -- Value of "a1" attribute
 AND   t1.id = t2.id
 AND   t2.b1 = "BB1"  -- Value of "b1" attribute
 AND   t2.b2 = "BB2"  -- Value of "b2" attribute

Is there an elegant way of doing this in Sybase ASE (12 or 15) which scales well as we increase the # of tables and attributes?

By “scale” I mean ~10-20 attributes needed across 4-5 joined tables

I can think of the following solutions, all of which seem to suck:


SOLUTION 1: Obvious: Join AV table, once per attribute

SELECT *
FROM   t1
      ,t2
      ,av AS 'av_a1'
      ,av AS 'av_b1'
      ,av AS 'av_b2'
WHERE  t1.a1 = av_a1.value
 AND   t1.id = t2.id
 AND   t2.b1 = av_b1.value
 AND   t2.b2 = av_b2.value
 AND   av_a1.attribute = "a1"
 AND   av_b1.attribute = "b1"
 AND   av_b2.attribute = "b2"

Pros: Obvious.

Cons: Scales VERY poorly as far as code quality, and probably performance as well.


SOLUTION 2: Avoid the headache of multiple joins with variables

declare @a1 varchar(255)
select  @a1 = value FROM av WHERE attribute = "a1"
declare @b1 varchar(255)
select  @b1 = value FROM av WHERE attribute = "b1"
declare @b2 varchar(255)
select  @b2 = value FROM av WHERE attribute = "b2"

SELECT *
FROM   t1
      ,t2
WHERE  t1.a1 = @a1
 AND   t1.id = t2.id
 AND   t2.b1 = @b1
 AND   t2.b2 = @b2

Pros: No more extra joins making the query both ugly and poorly performing.

Cons: Scales somewhat poorly as far as code quality (need to add new variables with new attributes).


Any better solutions?

  • 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-06-17T17:41:44+00:00Added an answer on June 17, 2026 at 5:41 pm

    I’m not sure what the additional clauses in the where statement are for (comparing values in one table to the attributes in the other). The following flattens the attributes before the join:

    SELECT *
    FROM   t1 join
           t2
           on t1.id = t2.id join
           (select av.id,
                   MAX(case when av.attribute = 'a1' then av.value end) as a1,
                   MAX(case when av.attribute = 'b1' then av.value end) as b1,
                   MAX(case when av.attribute = 'b2' then av.value end) as b2
            from av
            group by av.id
           ) attr
           on attr.id = t1.id
    

    This works, assuming there are no duplicates in the attributes — which there generally are not when using an attribute table. You can add back in the where conditions, if you like, I just didn’t understand why they were there.

    Also, you should switch to ANSI standard join syntax.

    If you don’t have an id, you can do essentially the same thing:

    SELECT *
    FROM   t1 join
           t2
           on t1.id = t2.id cross join
           (select MAX(case when av.attribute = 'a1' then av.value end) as a1,
                   MAX(case when av.attribute = 'b1' then av.value end) as b1,
                   MAX(case when av.attribute = 'b2' then av.value end) as b2
            from av
           ) attr
           on attr.id = t1.id
    where <whatever you want>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html table that looks something like this <table id=eventTable> <thead> <tr><th>#</th><th>Options</th></tr>
I have a table TABLES_IDS that looks like this: Table_ID Table_Name Table_Column -------- ----------
I have a view model that has a property that looks like this Property
I've got a table that looks like this: CREATE TABLE CustomerXmlData (CustomerId int, CustomerData
I have a xsd file that looks like this: <xs:schema attributeFormDefault=unqualified elementFormDefault=qualified xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:element
I have an XML data file that looks like this: <Sales> <Store Number=8 Date=2012-08-20T03:00:00>
i have xml file that looks like this: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE pointList SYSTEM
I have a database that looks as follows: attribute id - value 64 -
I have two tables that look like this: Table A: +-----+-----+------+-------+ | aID |
I have a function that returns the highest value of an attribute in an

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.