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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:16:27+00:00 2026-05-13T19:16:27+00:00

I am new to SQL, and have two tables that hold data(I am using

  • 0

I am new to SQL, and have two tables that hold data(I am using Adodb). They both have keys that connect them together, so I wanted to select a name from the first table if that has a parent id in the second table. I am using:

$db->GetCol("SELECT x_ast.name FROM x_ast, x_ast_tree WHERE x_ast_tree.parent='$parent_id'");

This returns an array with the correct data, but it is in there twice. (I assume because I asked it to come from two tables):

Array
(
    [0] => Trash
    [1] => Users
    [2] => admin
    [3] => Trash
    [4] => Users
    [5] => admin
)

How can I select a field from one table based on the data in another table, but only return one set of results? What am I doing wrong?

  • 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-13T19:16:27+00:00Added an answer on May 13, 2026 at 7:16 pm

    The problem is that you haven’t set a criterion for joining the two tables, so it’s doing a cross join.

    SELECT x_ast.name
    FROM x_ast
    INNER JOIN x_ast_tree
      ON x_ast.somefield=x_ast_tree.somefield
    WHERE x_ast_tree.parent='$parent_id'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new in sql. I have doubt. Let's say that I have two tables.
I have two tables that i am inserting records into. I am using PHP
I am using LINQ to SQL in my project. I have two tables Category
I'm new to SQL, so this isn't too complicated. I have two tables, with
High level I have two tables that need to have some of the data
I'm simply trying to get data from two sql server db tables using ado.net
I have two tables (tbl and tbl_new) that both use the same sequence (tbl_id_seq).
Let's assume that I have two tables... Foo and Bar. They contain the following
I am creating a new SQL Server 2008 database. I have two two tables
I am pretty much new to using SQL Server 2000. I have been using

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.