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

  • Home
  • SEARCH
  • 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

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 a migration that runs an SQL script to create a new Postgres
I am new to sql so please bear with me here. I have two
Hi I'm very new to sql but have been passed a job in which
I am totally new to SQL . I have a simple select query similar
I am new to SQL Server, and I have been tasked with setting permissions
Imagine I have two tables: PETS SPECIES The SPECIES table has two columns: ID
This is a tough question to word...so bear with me. I have two tables
I'm loading a SQL Server 2000 database into my new SQL Server 2005 instance

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.