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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:46:44+00:00 2026-05-29T21:46:44+00:00

I have a database table structure as follow: datatype data mytable now datatype has

  • 0

I have a database table structure as follow:

datatype
data
mytable

now datatype has primary key datatypeid, data table has datatypeid as foriegn key and has mytable id as foreign key.

In datatype I have a column called description which has address1, address2 etc

And the values for these addresses are stored in data table using the datatypeid as reference.

So I want to make a select statement to show the ids from mytable and address1, address2 etc as columns, with the values coming from data.values as follow:

id address1  address2
1  test add  test add2
2  test add  test add2
2  test add  test add2

here is my query so far but it outputs it in different format:

SELECT     id
FROM       datatype 
INNER JOIN data ON datatype.DataTypeID = data.DataTypeID 
INNER JOIN mytable ON data.ID = mytable.ID

EDIT :
table structure:

datatype 
  -datatypeid int
  -description varchar(50)
data
  -id int
  -datatypeid int
  -datavalue varchar(50)
  -mytableid int
mytable
  -mytableid int
  -datecreated datetime

Sample Data

datatype :
datatypeid  description
1           address1
2           address2

data :
id datatypeid datavalue        mytableid
1   1         george street     1

mytable:
mytableid datecreated
1         2012-02-17 10:06:02.507

Can you help please?

  • 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-29T21:46:46+00:00Added an answer on May 29, 2026 at 9:46 pm

    spitballing this, but give it a try

    SELECT m.mytableid, CASE WHEN dt.datatypeid = 1 AND d.datatypeid =1 THEN d.datavalue ELSE null END AS "address1"
        , CASE WHEN dt.datatypeid = 2 AND d.datatypeid =2 THEN d.datavalue ELSE null END AS "address2"
        ,m.datecreated    
    FROM datatype dt inner join
        data d on dt.datatypeid = d.datatypeid inner join
        mytable m on d.mytableid = m.mytableid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+
I have a database structure that has a Person table which contains fields such
I have two database tables with the following structure: actions: action_id int(11) primary key
I have a few classes, such as those that outline database table structure or
I have a database the I am rebuilding the table structure was crap so
I have no control over database schema and have the following (simplified) table structure:
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a table in my database which stores a tree structure. Here are
I have created a table on an Oracle 10g database with this structure :
I have database table whose structure is as follows: id int name varchar(20) dob

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.