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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:17:08+00:00 2026-06-16T07:17:08+00:00

I have the following scheme: CREATE TABLE IF NOT EXISTS `connections` ( `username1` varchar(15)

  • 0

I have the following scheme:

CREATE TABLE IF NOT EXISTS `connections` (
`username1` varchar(15) NOT NULL,
`username2` varchar(15) NOT NULL,
PRIMARY KEY (`username1`,`username2`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `connections` (`username1`, `username2`) VALUES
('guy', 'maricela'),
('maricela', 'guy'),
('mikha', 'guy');

CREATE TABLE IF NOT EXISTS `users` (
`username` varchar(15) NOT NULL,
`first_name` varchar(50) NOT NULL,
`last_name` varchar(50) NOT NULL,  
PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `users` (`username`, `first_name`, `last_name`) VALUES
('maricela', 'Maricela', 'Ros'),
('mikha', 'Michael', 'Samuel'),
('guy', 'Guy', 'Marquez');

The scheme contains 2 tables; one for user info called users with info first name,last name, and username. The 2nd table is connections. The column connections.username1 is the one who follows and connections.username2 is the one who is followed. I want to output a list of the people who follow the user maricela and for each result check if the resulting user is followed by the user mikha or not.

I use the following query but checking if the result is followed by mikha isn’t working:

SELECT followed_by_mikha.username AS followed_by_mikha,
   users.first_name,
   users.last_name,       
   users.username      
   FROM connections
   LEFT JOIN users ON users.username = connections.username1
   LEFT JOIN users followed_by_mikha ON (connections.username1 = 'mikha' AND connections.username2 = users.username AND connections.username2 = followed_by_mikha.username)
   WHERE connections.username2 = 'maricela'
   ORDER BY users.username DESC LIMIT 10

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-16T07:17:09+00:00Added an answer on June 16, 2026 at 7:17 am
    SELECT fbm.username2 AS followed_by_mikha,
       users.first_name,
       users.last_name,       
       users.username      
       FROM connections
       LEFT JOIN users ON users.username = connections.username1
    
       LEFT JOIN connections fbm ON fbm.username2=connections.username1 and fbm.username1 = 'mikha'
    
       WHERE connections.username2 = 'maricela'
       ORDER BY users.username DESC LIMIT 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scheme: CREATE TABLE IF NOT EXISTS `answers` ( `id` bigint(20)
I have a table with the following schema: CREATE TABLE IF NOT EXISTS `feeds`
I have the following table schema: CREATE TABLE [Foo]( [id] [int] NOT NULL, [name]
I have the following pseudo-SQL schema: table flight id int primary key date timestamp
I have two tables with the following schema: CREATE TABLE sales_data ( sales_time date
I have the following schema, which I've simplified slightly: CREATE TABLE [dbo].[Header] ( [HeaderId]
I have the following schema and related data. -- Schema CREATE TABLE [PERSON] (
I have the following table in my iSeries DB2 schema: CREATE TABLE LATHAM1.SGINES1.LICVP010 (ID
I have an entity class with the following annotation on its primary key: @GeneratedValue(strategy
I have 3 tables with the following schema: CREATE TABLE `devices` ( `device_id` int(11)

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.