question

MH7342 avatar image
MH7342 asked

Using different "WHERE =" parameters for different parts of query

I have the below query that I want it to have its own "new" column in a bigger query. I need to create new columns of data that have different "Where = " parameters for each column because I can't "Create" or "Alter" anything in our database. Should I be creating a subquery? If so how should I start doing that? Thanks so much!! **SELECT GLX.MX_VALUE FROM [LSLMDB].[ls_apps].GLACCMXVAL GLX WHERE GLX.MATRIX_CAT = 'BALSHEET '**
subquerywhere
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What's the bigger query you have in mind? How does it relate to this query - can they be joined on a particular column(s)? You can use subqueries to combine queries with different WHERE clauses but, if they don't relate to each other (you can't join them), it probably wouldn't make sense to combine them into a larger query.
1 Like 1 ·
I think I get what you're saying. They do relate to each other but maybe I should give you an example. The larger query is something like this: Account# Description Attribute Value 100 Cash Red A 100 Cash Blue 1 200 Check Red AA 200 Check Blue 11 Each account has two different attributes and I want to have a column that groups everything by the attribute Red, and then have another column that groups everything by Blue. Does that make sense? I don't want a column that lists everything by Attribute, I want a column that says Red and lists everything below that connected to Red and then another column for Blue. The only way I can join the tables I need together is through the account ID's. The attribute table and the account table have the same ID's and that join works but I can't group them by attribute because it sees multiple attributes.
0 Likes 0 ·
Do you want "Red" and "Blue" to be the column names then list the associated values within those columns? Is this looking close to what you are after? SELECT * FROM (select [Account#], Description, Value as [Attribute_Red] from where Attribute = 'Red') as Red_Source inner join (select [Account#], Description, Value as [Attribute_Blue] from where Attribute = 'Blue') as Blue_Source on Red_Source.[Account#] = Blue_Source.[Account#] Hopefully, that would turn out something like this: Account# Description Attribute_Red Attribute_Blue --------------------------------------------------------- 100 Cash A 1 200 Check AA 11
0 Likes 0 ·

1 Answer

·
MH7342 avatar image
MH7342 answered
Thank you and sorry for taking so long to get back to you! I think that will work, I'll have to wrap my mind around it again because I've had to divert for a few weeks and work on my "regular" work. I'll give it a go in the next few days but I think this might work. Are those called "subselect" queries?
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.