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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:23:10+00:00 2026-05-30T14:23:10+00:00

I have 4 tables. Users, Articles, Langs, LangList Articles table: …, uid (Users.id), lang

  • 0

I have 4 tables. Users, Articles, Langs, LangList

Articles table: …, uid (Users.id), lang (Langs.id),…

LangList table: id, uid (Users.id), langid (Langs.id)

I want to select all those articles for a specified user (ex. Users.id = 66), where are in his selected languages list.

If i make this:

function FindActiveLangs($lang){
    $sql ="SELECT langid FROM LangList WHERE `uid`= '66' AND `active`='1';";
    $rsd = mysql_query($sql);
    $lang_string = " ( ".$lang."lang = '0' ";
    while($row = mysql_fetch_array($rsd)){
        $lang_string .= " OR ".$lang."lang = '".$row['langid']."' ";
    }
    $lang_string .= " ) ";
    return $lang_string;
} //end of FindActiveLangs


$tables = " Articles ";
$lang_string = FindActiveLangs("Articles.");
$where1 = "WHERE ".$lang_string." ";
$sql = "select distinct Articles.id, title, descr, thumb, relDate, 
            Articles.alias, Articles.lang, author, source  
        from ".$tables.$where1." and Users";

I took the results in 0.01-0.03 secs

In the second way, that I think is better for clean code:

$sql = "select distinct Articles.id, title, descr, thumb, relDate, 
            Articles.alias, Articles.lang, author, source  
        from Articles 
        where lang IN 
            (SELECT langid FROM LangList WHERE uid= '66' AND active='1')";

I took the results in 1.1-1.3 secs

Is there any way to execute this query, with second way with better performance? the “IN” kills the speed

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-30T14:23:12+00:00Added an answer on May 30, 2026 at 2:23 pm

    look at EXISTS instead of IN. The performance is much better.

    select distinct Articles.id, title, descr, thumb, relDate, Articles.alias, Articles.lang, author, source  
    from Articles, TagsList 
    where
        Articles.lang = 0 OR 
        EXISTS 
              (SELECT *
               FROM LangList 
               WHERE uid= '66' AND active='1' 
               AND langid = Articles.lang)
    

    EDIT: second attempt (check if the performance is any better):

    SELECT Articles.*
       FROM Articles 
        INNER JOIN LangList
            ON langid = Articles.lang
       WHERE uid= '66' AND active='1' 
    
    UNION
    
    SELECT Articles.*
    FROM Articles
    WHERE 
    Articles.lang=0
    AND
    NOT EXISTS
    (
        SELECT *
               FROM LangList 
               WHERE uid= '66' AND active='1' 
               AND langid = Articles.lang
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want
Here i need help with joins. I have two tables say articles and users.
I have two tables in my database users table : +-----------+---------------------+---------+---------+ | id |
I have this query SELECT articles.*, users.username AS `user` FROM `articles` LEFT JOIN `users`
I have three tables (users, articles, and tags) defined in SQLAlchemy and mapped with
I have two tables -- an article table and a vote table. Users can
I have 2 tables. Table 1 is 'articles' and Table 2 is 'article_categories'. When
I have a table of Users: id, type, name and a table of Articles:
I have a table of users, some of which have articles associated with them,
I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id,

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.