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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:04:49+00:00 2026-06-10T01:04:49+00:00

I have a profiles table with userid key key_value obviously userid can have many

  • 0

I have a “profiles” table with

  1. userid
  2. key
  3. key_value

obviously userid can have many rows
when a user logs in, I store userdata in a session_var
the query uses 3 tables:

  1. users
  2. profiles
  3. openid

I had this,

$sql = "SELECT op.provider, g . * , gp . *, CONCAT(g.firstname, ' ', g.lastname) AS fullname
    FROM openid AS op
    INNER JOIN users AS g ON g.userid = op.userid
    INNER JOIN profiles AS gp ON gp.userid = op.userid
    WHERE op.openid =$openid";

but it returns multiple rows with duplicate data depending how many rows there are in the “profiles” table

This is not what I want. I need all the data in one row if that is possible

What is the most efficient solution? I also need it to store in a php array. How does php handle duplicate keys?

  • 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-10T01:04:51+00:00Added an answer on June 10, 2026 at 1:04 am

    You probably want something like a distinct :

    $sql = "SELECT distinct op.provider, g . * , gp . *, CONCAT(g.firstname, ' ', g.lastname) AS fullname
        FROM openid AS op
        INNER JOIN users AS g ON g.userid = op.userid
        INNER JOIN profiles AS gp ON gp.userid = op.userid
        WHERE op.openid =$openid";
    

    That or you use a group by with the columns you want to have data grouped by.

    Lastly, if you want to return multiple rows of data into a single field (but they are different) you could use a mysql group_concat() function to do so:

    mysql> select * from first;
    +------+-------+
    | id   | title |
    +------+-------+
    |    1 | aaaa  |
    |    2 | bbbb  |
    |    3 | cccc  |
    +------+-------+
    3 rows in set (0.00 sec)
    
    mysql> select group_concat(id) as IDs, group_concat(title) as Titles from first;
    +-------+----------------+
    | IDs   | Titles         |
    +-------+----------------+
    | 1,2,3 | aaaa,bbbb,cccc |
    +-------+----------------+
    1 row in set (0.00 sec)
    

    Okay, I added some extra rows to my example table like this:

    mysql> select * from first;
    +------+-------+
    | id   | title |
    +------+-------+
    |    1 | aaaa  |
    |    2 | bbbb  |
    |    3 | cccc  |
    |    4 | NULL  |
    |    5 | eeee  |
    +------+-------+
    5 rows in set (0.00 sec)
    

    and now a group_concat returns this:

    mysql> select group_concat(id) as IDs, group_concat(title) as Titles from first;
    +-----------+---------------------+
    | IDs       | Titles              |
    +-----------+---------------------+
    | 1,2,3,4,5 | aaaa,bbbb,cccc,eeee |
    +-----------+---------------------+
    1 row in set (0.00 sec)
    

    But you can add a nice placeholder using the coalesce() function nicely like this:

    mysql> select group_concat(id) as IDs, group_concat(coalesce(title,'NoValueSpecial')) as Titles from first;
    +-----------+------------------------------------+
    | IDs       | Titles                             |
    +-----------+------------------------------------+
    | 1,2,3,4,5 | aaaa,bbbb,cccc,NoValueSpecial,eeee |
    +-----------+------------------------------------+
    1 row in set (0.01 sec)
    

    The coalesce() function looks at either multiple columns or a value you manually enter like I did and returns a great identifier to spot your missing field. It will evaluate left to right for the null values.

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

Sidebar

Related Questions

I have a database table for user profiles. It's comprised of a primary key,
I have a table that has account numbers in (account_num) and user profiles (profile_id).
Below is my table, a User could have multiple profiles in certain languages, non-English
using php and mysql I have two tables, a users table and a profiles
I have a website that contains company profiles. These profiles have many pages within
I have 2 tables (Users, Wall). The UserID in the Wall table is a
I have a table User and a table Profile. Here's what I have in
I have the following query (user_id isn't and can't be primary key as there
I have tables in a MySQL database like this... CREATE TABLE `someUserTable` ( userId
I have two tables: Users and Profiles. A user may have a profile and

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.