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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:47:14+00:00 2026-06-18T01:47:14+00:00

Hope someone will help me to build this query. I need to get values

  • 0

Hope someone will help me to build this query. I need to get values from database which are belong to one particular user. These are the columns which I need to get.

01. city_name // From city table
02. district_name // From district table
03. category_name // From category table
04. subscription_period // From tutors table
05. date_registered // From tutors table

I have already got values tutor_id, city_id and category_id respectively 1, 53, 5

My address table has city_id column, City table has district_id column, category table has category_id column and tutor table has tutor_id and address_id.

I tried something like this, but this is not working.

SELECT city_name, district_name, category_name, subscription_period AS sp, date_registered AS date
FROM tutors AS t
INNER JOIN district AS d 
INNER JOIN city ON city.district_id = d.district_id
INNER JOIN address ON address.city_id = 50
INNER JOIN category
WHERE t.tutor_id = 1 AND category.category_id= 5

My expecting result should have 1 row as output but this query give me more rows as output

My SQL Tables

CREATE TABLE tutors (
tutor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
address_id SMALLINT NOT NULL,
tutor_name VARCHAR(80) NOT NULL,
subscription_period SMALLINT NOT NULL,
date_registered TIMESTAMP  NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tutor_id)
); 

CREATE TABLE address (
address_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
address VARCHAR(40) NOT NULL, 
city_id SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (address_id)
);

CREATE TABLE district(
district_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
district_name VARCHAR(30) NOT NULL, 
PRIMARY KEY (district_id)
);

CREATE TABLE city(
city_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
city_name VARCHAR(30) NOT NULL, 
district_id SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (city_id)
);

CREATE TABLE category (
category_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
category_name VARCHAR(60) NOT NULL, 
PRIMARY KEY (category_id)
);

CREATE TABLE tutor_category(
tutor_id SMALLINT UNSIGNED NOT NULL,
category_id SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (tutor_id)
);
  • 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-18T01:47:15+00:00Added an answer on June 18, 2026 at 1:47 am

    Try something like this:

    SELECT c.city_name, 
           d.district_name, 
           c.category_name, 
           t.subscription_period AS sp, 
           t.date_registered AS date
    FROM tutors t
       INNER JOIN address a ON t.address_id = a.address_id 
       INNER JOIN city c ON c.city_id  = a.city_id 
       INNER JOIN district d ON c.district_id = d.district_id 
       INNER JOIN tutor_category tc on t.tutor_id = tc.tutor_id 
       INNER JOIN category cat on tc.category_id = cat.category_id 
    WHERE t.tutor_id = 1 AND cat.category_id= 5 AND c.city_id = 50
    

    You need to JOIN on your tables to ensure you only receive the desired results.

    If you are receiving duplicate rows that are identical, you are probably doing something wrong or the definitions you provided are not correct (it appears that this is the case indeed). You could “solve” the issue by adding GROUP BY or DISTINCT to your query but that is not the best approach.

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

Sidebar

Related Questions

I tried everything to get this code working, and I hope someone will save
Hope someone can help i cant seem to get my head around this, i
I really hope someone will be able to help me out with this. I
Hope someone can help me out with this one ! I have a sql
I'm new to CakePHP and hope someone could help me with this one. I
Hope someone will give me a hand with this problem I have. So here
Hope someone could help me with this: I would like to have a column
Hope someone has an easy answer on this. I have a header image which
Hope someone can help me out with this problem I am having. I just
I hope someone can help me here. I'm having trouble loading this variable. Right

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.