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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:37:00+00:00 2026-05-18T22:37:00+00:00

LookupTable: userid, mobileid, startedate, enddate , owner 1 , 1 , 12-12-2000, 01-01-2001, asd

  • 0

LookupTable:

userid, mobileid, startedate, enddate   , owner
1     , 1       , 12-12-2000, 01-01-2001, asd 
2     , 2       , 12-12-2000, 01-01-2001, dgs
3     , 3       , 02-01-2001, 01-01-2002, sdg
4     , 4       , 12-12-2000, 01-01-2001, sdg

UserInfoTable:

userid, firstname, lastname, address
1     , tom      , do      , test 
2     , sam      , smith   , asds
3     , john     , saw     , asdasda
4     , peter    , winston , near by

Mobile:

Mobileid, Name        , number, imeinumber
1       , apple       , 123   , 1111111
2       , nokia       , 456   , 2222222 
3       , vodafone    , 789   , 3333333

CallLogs:

id       , Mobileid, callednumbers (string), date         , totalduration
1        , 1       , 123,123,321           , 13-12-2000   , 30
2        , 1       , 123,123,321           , 14-12-2000   , 30
3        , 2       , 123,123,321           , 13-12-2000   , 30
4        , 2       , 123,123,321           , 14-12-2000   , 30
5        , 3       , 123,123,321           , 13-12-2000   , 30
6        , 3       , 123,123,321           , 14-12-2000   , 30
7        , 1       , 123,123,321           , 13-01-2002   , 30
8        , 1       , 123,123,321           , 14-01-2002   , 30

I want a query which will return me the following:

firstname, lastname, mobile.name as mobilename, callednumbers (as concatinated strings from different rows in CallLogs table) and need it for year 2000
example:

firstname, lastname, mobilename, callednumbers
tom      , do      , apple     , 123,123,321, 123,123,321
sam      , smith   , nokia     , 123,123,321, 123,123,321
peter    , winston , apple     , 123,123,321, 123,123,321

any help will be highly appreciated…

I have tried this but no sucess.. tom is getting sams calls and vice versa. I am using sql server.

SELECT DISTINCT firstname,
                lastname,
                mobilename,
                callednumbers
FROM   ([testdatabase].[dbo].[LookupTable] lt
        INNER JOIN [testdatabase].[dbo].[UserInfoTable] user1
          ON lt.userid = user1.id)
       INNER JOIN [testdatabase].[dbo].[Mobile] device1
         ON lt.mobileid = device1.id
       INNER JOIN [testdatabase].[dbo].[CallLogs] log1
         ON lt.mobileid = log1.deviceid
WHERE  lt.starttime LIKE '%2000%'
ORDER  BY firstname  
  • 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-18T22:37:01+00:00Added an answer on May 18, 2026 at 10:37 pm
    DECLARE @LookupTable TABLE (
      userid     INT,
      mobileid   INT,
      startedate DATETIME,
      enddate    DATETIME,
      owner      CHAR(3))
    
    INSERT INTO @LookupTable
    SELECT 1, 1, '20001212 00:00:00.000', '20010101 00:00:00.000', N'asd' UNION ALL
    SELECT 2, 2, '20001212 00:00:00.000', '20010101 00:00:00.000', N'dgs' UNION ALL
    SELECT 3, 3, '20010102 00:00:00.000', '20020101 00:00:00.000', N'sdg' UNION ALL
    SELECT 4, 4, '20001212 00:00:00.000', '20010101 00:00:00.000', N'sdg'
    
    
    DECLARE @UserInfoTable TABLE (
      userid    INT,
      firstname VARCHAR(10),
      lastname  VARCHAR(10),
      address   VARCHAR(10))
    
    INSERT INTO @UserInfoTable
    SELECT 1, N'tom', N'do', N'test' UNION ALL
    SELECT 2, N'sam', N'smith', N'asds' UNION ALL
    SELECT 3, N'john', N'saw', N'asdasda' UNION ALL
    SELECT 4, N'peter', N'winston', N'near by'
    
    DECLARE @Mobile TABLE (
      mobileid   INT,
      name       VARCHAR(10),
      number     INT,
      imeinumber INT )
    
    INSERT INTO @Mobile
    SELECT 1, N'apple', 123, 1111111 UNION ALL
    SELECT 2, N'nokia', 456, 2222222 UNION ALL
    SELECT 3, N'vodafone', 789, 3333333
    
    DECLARE @CallLogs TABLE (
      id            INT,
      mobileid      INT,
      callednumbers VARCHAR(50),
      [date]        DATETIME,
      totalduration INT )
    
    INSERT INTO @CallLogs
    SELECT 1, 1, N'123,123,321', '20001213 00:00:00.000', 30 UNION ALL
    SELECT 2, 1, N'123,123,321', '20001214 00:00:00.000', 30 UNION ALL
    SELECT 3, 2, N'123,123,321', '20001213 00:00:00.000', 30 UNION ALL
    SELECT 4, 2, N'123,123,321', '20001214 00:00:00.000', 30 UNION ALL
    SELECT 5, 3, N'123,123,321', '20001213 00:00:00.000', 30 UNION ALL
    SELECT 6, 3, N'123,123,321', '20001214 00:00:00.000', 30 UNION ALL
    SELECT 7, 1, N'123,123,321', '20020113 00:00:00.000', 30 UNION ALL
    SELECT 8, 1, N'123,123,321', '20020114 00:00:00.000', 30
    
    SELECT DISTINCT firstname,
                    lastname,
                    device1.name AS mobilename,
                    stuff((select ',' + callednumbers 
                           from @CallLogs log1 
                           where lt.mobileid = log1.mobileid 
                           for xml path('')), 1, 1, '') AS callednumbers 
    FROM   (@LookupTable lt
            INNER JOIN @UserInfoTable user1
              ON lt.userid = user1.userid)
           INNER JOIN @Mobile device1
             ON lt.mobileid = device1.mobileid
    WHERE  lt.startedate > '20000101' AND  startedate < '20010101'
    ORDER  BY firstname  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables in my SQL database as follows Users2 UserID, EID, Name,
I have the following database structure: CREATE TABLE LookupTable ( PK UNIQUEIDENTIFIER PRIMARY KEY,
how would i set this to null; LookupTable<Product *> table; everything i try says
When designing a lookup table (enum) in SqlServer 2005, if you know the number
Are the old tricks (lookup table, approx functions) for creating faster implementations of sqrt()
Is empty lookup table the same as non-matching lookup table in lookup transform? What
I'm trying to save some lookup table data out to a YAML file so
Let's say I have a lookup table which I'd like to make accessible to
I am trying to code a global lookup table of sorts. I have game
Will there be any further resultset to process if the lookup table in the

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.