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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:12:55+00:00 2026-06-05T17:12:55+00:00

I currently have a MySQL table like: id | friend 1 | 2 1

  • 0

I currently have a MySQL table like:

id | friend
1  |   2
1  |   5
1  |   10
3  |   6
15 |   19
21 |   4

I’m trying to grab all the friend id’s of one particular user and arrange them into a comma-delimited list. For example, grabbed user1’s friends, it would return as

$friend_list = 2,5,10

Currently, I have:

$sql = "SELECT friend FROM table__friends WHERE id = ".$user_id;

This only grabs one row though..please help!

Thanks

  • 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-06-05T17:12:56+00:00Added an answer on June 5, 2026 at 5:12 pm

    You want to use GROUP_CONCAT :

    $sql = "SELECT GROUP_CONCAT(friend) FROM table__friends GROUP BY id HAVING id = ".$user_id;
    

    Adjusted for correctness per the better answer.

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

Sidebar

Related Questions

I'm trying to normalize a mysql database.... I currently have a table that contains
I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
I have a table in MySQL 4.0 which currently has a year field as
I currently have a MySQL table of about 20 million rows, and I need
I have three tables, table one (tableA) containing users data like name and email,
I currently have a large table in MySQL with several fields. I am currently
I currently have the following MySQL query, which I would like to include in
I currently have a MySQL table called _post and i have a column called
I have a MySQL table of financial transactions. The table is like so: +----+-----------+--------+--------+---------+---------+
If I have an array like: $b=array(1,6,8,9); and I also have a mysql table

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.