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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:35:32+00:00 2026-05-15T18:35:32+00:00

SELECT user.login, book.name FROM user LEFT JOIN book ON user.login = book.author WHERE user.login

  • 0

SELECT user.login, book.name
FROM user
LEFT JOIN book ON
user.login = book.author
WHERE user.login = ‘peter’

Now i get:

peter book1
peter book2
peter book2

Bu i wish get:

peter book1
      book2
      book2

Database: MySQL
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-05-15T18:35:33+00:00Added an answer on May 15, 2026 at 6:35 pm

    I agree with others that while this is something that can be performed in SQL, it really shouldn’t be.

    The following assumes that there can be only one author per book, which is not the case in reality:

    SELECT x.author,
           x.book_name
      FROM (SELECT CASE 
                     WHEN @author != u.login THEN u.login
                     ELSE ''
                   END AS author, 
                   b.name AS book_name,
                   @author := u.login AS set_variable  
              FROM USER u
         LEFT JOIN BOOK b ON b.author = u.login
              JOIN (SELECT @author := '') r
             WHERE u.login = 'peter'
          ORDER BY u.login) x
    

    It uses a variable (only MySQL supports this, to my knowledge) to store the author/login value. The CASE expression is set to return the column value if it does not match what is currently stored in the variable. If the variable and the column value match, a zero length string will occupy the column value – you could change this to be NULL if you like.

    I included an ORDER BY in the likelihood you’d want this to happen for multiple names, because there’s no way to guarantee data order without an ORDER BY.

    I had to use a subquery, otherwise, the column where the variable gets set would appear in your resultset.

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

Sidebar

Related Questions

Consider this T-SQL: CREATE USER my_test_user WITHOUT LOGIN; SELECT USER_NAME(), USER, SUSER_SNAME(),SYSTEM_USER, suser_name(); EXECUTE
Say I have the following: $query = SELECT user_id,email,password, roles.role_id,role_name FROM users JOIN roles
I have a query like this SELECT user_id FROM user WHERE user_id NOT IN
SQL: select * from user where room_id not in (select id from rooms); what
This line: $quey1=select * from clients WHERE USER == $current_user->user_login;; It returns an unknown
On my website I want the user to have the ability to login/logout from
I my application I do not want the same user name login at the
I have a OrganisationName select box in Edit/Add User Page. <s:select key=user.organisationname name=entity.organisationId list=organisationList
SELECT user_id, created FROM photo_comments GROUP BY user_id returns user_id created 1 2009-10-20 21:08:22
cursor.execute(SELECT user_id FROM myapp_location WHERE\ GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(PointFromWKB(point(%s, %s)))))) < %s\ ,(user_utm_easting, user_utm_northing, 500)); This

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.