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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:22:39+00:00 2026-05-26T10:22:39+00:00

I have an SQL query which displays 2 rows retrieved but when I echo

  • 0

I have an SQL query which displays 2 rows retrieved but when I echo the field name nothing is retrieved. Anyone know what I am doing wrong?

$sql = 'SELECT *
FROM tag_map
LEFT JOIN tags2 ON tags2.tag_id = tag_map.tag_id
LEFT JOIN video ON video.vid_id = tag_map.vid_id
WHERE tag_map.vid_id=?';
$stmt_tags = $conn->prepare($sql);
$result=$stmt_tags->execute(array($vid_id));
echo $tag_count=$stmt_tags->rowCount(); //shows 2
$tags = array();
while ($row = $stmt_tags->fetch(PDO::FETCH_ASSOC)) {
    echo $row['name'];
}

EDIT: Var_dump using suggested query

SELECT tag_map.*, tags2.name AS tag_name
FROM tag_map
LEFT JOIN tags2 ON tags2.tag_id = tag_map.tag_id
LEFT JOIN video ON video.vid_id = tag_map.vid_id
WHERE tag_map.vid_id=?


array(4) { ["id"]=> string(4) "1234" ["vid_id"]=> string(32) "8364a8e463052e215a5dc174c92a2f18" ["tag_id"]=> string(32) "4c71a73d001dd9c09c7d9d95907bf1fe" ["tag_name"]=> NULL } array(4) { ["id"]=> string(3) "123" ["vid_id"]=> string(32) "8364a8e463052e215a5dc174c92a2f18" ["tag_id"]=> string(32) "57bb5dd83dc84e7115387886e328b04b" ["tag_name"]=> NULL }
  • 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-26T10:22:39+00:00Added an answer on May 26, 2026 at 10:22 am

    You should be specific in your SELECT clause, particularly when joining other tables.

    For example

    SELECT tag_map.vid_id, tag_map.name, tags2.name AS tag_name
    

    Notice how I’ve used an alias for tags2.name to avoid a column name conflict with tag_map.name.

    I’m only guessing here but I’d say you have a name column in one of your left-joined tables that’s overriding tag_map.name.

    Update

    In light of the extra information, I’d have to say it’s solely due to your left-joins. The records where tags2.name is showing NULL simply do not have related fields in tag_map for the vid_id in question.

    If you only want to show records where there is a relation between tag_map and tags2, use INNER JOIN

    Demo here – http://sqlize.com/UL1M80DT0c

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have this SQL query which is valid but always times out:
I have an Informix SQL query which returns a set of rows. It was
i've got a SQL query which returns multiple rows, and i have : $data
I have written SQL query which brings data from multiple tables and displays the
Can we have a SQL query which will basically help in viewing table and
I have a SQL SELECT query which has a LIKE clause containing an underscore,
I have SQL query, which is working nice on Oracle and MSSQL. Now I'm
I have been asked in an interview to write a SQL query which fetches
Strange performance outcome, I have a LINQ to SQL query which uses several let
I have the following which works in SQL Query Analyzer . select oh.* from

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.