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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:08:17+00:00 2026-05-26T05:08:17+00:00

Can I get some help with this query. I will explain in details. To

  • 0

Can I get some help with this query. I will explain in details. To make it easier I’ll take an example with HTML tags and attributes.

I have 3 table:

  • tbl1 – contains all the HTML tags (tagId, tagName)
  • tbl2 – contains all the available attributes that might appear in the
    tags (attId, attName)
  • tbl3 – is a map table for tbl1 and tbl2 (tagId, attId)

I want to select all the attributes (and related information about the attributes) that belong to the chosen tag (in the example below tag id 4) and the ID of the tag.

Here is an example of what I’d like to get from the query:

attId  tagId   attName  
50     4       The name of the attribute with id 50
89     4       The name of the attribute with id 89
114    4       The name of the attribute with id 114

Below is the query that I’ve made, but I believe there is a better way.

SELECT tbl2.*, tbl3.tagId
FROM tbl2 JOIN tbl3 
WHERE tbl3.attId IN (
     SELECT tbl3.attId FROM tbl3 where tbl3.tagId=4
     )
AND tbl3.attIdd = tbl2.attId
GROUP BY tbl3.attId

Thanks in advance.

  • 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-05-26T05:08:18+00:00Added an answer on May 26, 2026 at 5:08 am

    Issue 1
    You’re doing cross join that you later reduce to an inner join by putting a filter in the where clause.
    This is the old-skool way when using implicit join syntax.
    On most SQL-dialects (but not MySQL) this gives an error.
    Never do a join without a ON clause.
    If you want to do a cross join, use this syntax: select * from a cross join b

    Issue 2
    The sub select is really not needed, you can just do the test inside a where clause.

    SELECT tbl2.*, tbl3.tagId 
    FROM tbl2 
    INNER JOIN tbl3 ON (tbl3.attIdd = tbl2.attId)
    WHERE tbl3.tagId = 4 
    GROUP BY tbl3.attId 
    

    Issue 3a
    You are doing a group by on tbl3.ATTid, which in this context is the same as doing a group by on tbl2.attid (because of the ON (tbl3.attIdd = tbl2.attId) clause)
    The latter makes a bit more sense, because you are doing select tbl2.*, not select tbl3.*

    Issue 3b
    If attId is not a primary or unique key for tbl2, than the result of the query will be indeterminate.
    That means that the query will select a row at random from a list of possible rows with the same attID. If you don’t want that you’ll have to include a having clause that will choose a row based on some criterion.

    Example

    /*selects the most recent row per attID, instead of a random one*/
    SELECT tbl2.*, tbl3.tagId 
    FROM tbl2 
    INNER JOIN tbl3 ON (tbl3.attIdd = tbl2.attId)
    WHERE tbl3.tagId = 4 
    GROUP BY tbl2.attId 
    HAVING tbl2.dateadded = MAX(tabl2.dateadded) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hoping to get some help with this query, I've worked at it for a
Could I get some help creating this query please? Users book product video slots
Can I get some help posting across different pages from a custom control? I've
Is there anything which can help with msmq monitoring? I'd like to get some
this is a bit of a newbie question but hoping I can get some
how can i get some part of string (in symbols). For example: $string =
I need some help making a linq query that will select a list of
I'm creating a linq query to get some data that will return a list
I've been working on this for two days, can't get it, I need some
We'd like to see if we can get some improved performance for analysis and

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.