woolyg Posted June 14, 2007 Share Posted June 14, 2007 Hi all, I put this into the MSSQL forum also, but it'll relate to MySQL too. I'm running an SQL query that returns the following results: Value FirstName Surname Number NULL Mel Brooks 4 1001 JIm Jones 9652 13 JR Ewing 5 13 JR Ewing 9651 2 S R 2 5678 Euan S 6 8888 John Ryan 3 But I only want JR Ewing to show up once. Could anyone advise me on how to do this? I've tried using SELECT DISTINCT (Value), FirstName, SurName etc ..but it still shows up twice, as JR Ewing has 2 entries in the Number column. Can anyone help? Cheers Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/55518-solved-returning-only-one-entry-when-multiple-ones-show-up/ Share on other sites More sharing options...
DanDaBeginner Posted June 14, 2007 Share Posted June 14, 2007 use GROUP BY...... i.e. GROUP BY Surname Quote Link to comment https://forums.phpfreaks.com/topic/55518-solved-returning-only-one-entry-when-multiple-ones-show-up/#findComment-274389 Share on other sites More sharing options...
btherl Posted June 14, 2007 Share Posted June 14, 2007 If the numbers are unimportant, you can group by Value, FirstName, Surname, and simply not select the Number. The right query really depends on what you want to do with the Number column, which appears for each duplicate. Quote Link to comment https://forums.phpfreaks.com/topic/55518-solved-returning-only-one-entry-when-multiple-ones-show-up/#findComment-274422 Share on other sites More sharing options...
woolyg Posted June 14, 2007 Author Share Posted June 14, 2007 Cheers for the help guys. I went and bothered my resident SQL query guru (he wasn't happy, lemme tell ya) and he showed me the way you can call info from a table (say, table 'cards' defined as 'C') for one data instance using C1, then the next data instance using C2, and in the WHERE statement defining how to retrieve the C1 and C2 info. All highly confusing for me, but it made sense eventually! Solved- cheers. Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/55518-solved-returning-only-one-entry-when-multiple-ones-show-up/#findComment-274904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.