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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:47:06+00:00 2026-05-27T17:47:06+00:00

Background: i was first asked to do a website using mysql as the database,

  • 0

Background:

i was first asked to do a website using mysql as the database, after that was done and sent, the clients asked me to convert it to mssql, and 3 tiers.

i did the classes and functions for transferring data between the servers, so the 3 tiers bit is about halfway done. the thing i’m struggling with now is the MsSQL.

Question:

the MySQL version of the question looks like this:

select a.id as a_id, a.first_name, a.last_name, a.agent_code,
       b.id as b_id, b.user_id, b.status_admin 
from tbl_user a 
  inner join tbl_testimonia b 
    on a.id = b.user_id 
where b.status_admin=0  
group by a.id
order by b.id desc

what it does is return testimonials that aren’t approved yet, grouped to each user;


Where I am stuck:

i cant convert this to MSSQL

My best try:

  • Create view;

as in:

    create view test as
    (
    select a.id as a_id, a.first_name, a.last_name, a.agent_code,
    b.id as b_id, b.user_id,  b.status_admin 
    from tbl_user a inner join tbl_testimonia b on a.id = b.user_id 
    where b.status_admin=0 and a.id in  
    (
    select a.id from tbl_user a 
    inner join tbl_testimonia b 
    on a.id = b.user_id
    where b.status_admin=0 
    group by a.id
    )
    )

this selects what i want, but the id field of the create view cant be grouped, meaning the id field is not unique and can have the same value.

I guess my question up to this point is, how do i uniquely select the id field in the view?
sure i can do it in PHP, but i could have done that a month ago when i first encountered the problem.

I’ve been trying to find the answer for a while now but cant seem to find the answer unique to my question

  • edit: the MSSQL doesn’t work because even though the subquery is selecting unique ids the in statement in the main query makes this irrelevent
  • edit: example output::~ (in MySql the 3rd field is ommited)

    | a_id  |  firstN | LastN |  agent_code  |   b_id  |  user_id |status_admin|
    +--------------------------------------------------------------------------+
    | 32    |  fn1    | ln1   |  AC123213    |   14    |   32     |   0        |
    | 41    |  fn2    | ln2   |  12345678    |   15    |   41     |   0        |
    | 32    |  fn1    | ln1   |  AC123213    |   16    |   32     |   0        |
    
  • edit: QUESTION SOLVED a big thx to Lieven for the simple answer

  • 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-27T17:47:07+00:00Added an answer on May 27, 2026 at 5:47 pm

    As you have already explained yourself, unlike SQL Server, MySQL allows grouping by with unaggregated expressions like this

    SELECT  *
    FROM    mytable
    GROUP BY
            column
    

    As an unaggregated expression in GROUP BY returns an arbitrary record from each group and is not supposed to be used if the values vary you should be able to use the following statement as an equivalent in SQL Server

    select a.id as a_id
           , MIN(a.first_name)
           , MIN(a.last_name)
           , MIN(a.agent_code)
           , MIN(b.id as b_id)
           , MIN(b.user_id)
           , MIN(b.status_admin)
    from   tbl_user a 
           inner join tbl_testimonia b on a.id = b.user_id 
    where  b.status_admin=0  
    group by 
           a.id
    order by 
           b.id desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some background: VB.NET 2005 Application that accesses a MS-SQL back-end, using multiple Web
A bit of background first: I am using base code from a remote SVN
As usual, some background information first: Database A (Access database) - Holds a table
First a little background, I'm using jdk 1.6. I've got a 2 column table
I already asked same question here after that i came up with this code
Background: for my computer science class, we were asked to create a program that
The background: First of all, the background. I've created an infinite scrollview by using
A bit of background first: GeoModel is a library I wrote that adds very
A little background first: I'm designing a web application for a control system that
A little background first. I've been tasked with encrypting files with a Powershell script

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.