Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 double entry to single entry

Author  Topic 

leracj
Starting Member

13 Posts

Posted - 2013-06-23 : 22:28:50
having problems with the my sql code
i want it to post only unique ones

my sql code
SELECT ID, user_login, user_email, meta_value
FROM wp_users um, wp_usermeta u
WHERE user_id = ID
AND meta_key = 'first_name'

output:

ID /user_login /user_email /meta_value
1 ddwadmin info@ddwenterprises.com Dynamic
2 pfitzgerald patricefitzgerald@gmail.com Patrice
3 rleslie rk.leslie@gmail.com Richard
88 richard leslie richard_leslie@yahoo.com Richard
152 cedelen cheryledelen@gmail.com Cheryl
152 cedelen cheryledelen@gmail.com Cheryl
151 wgrossman wengros7@gmail.com Wendie
151 wgrossman wengros7@gmail.com Wendie
153 tyoney tazcdn@hotmail.com Theresa
153 tyoney tazcdn@hotmail.com Theresa
154 yyamaguchi yyamaguchi530@hotmail.com Yuki
154 yyamaguchi yyamaguchi530@hotmail.com Yuki
155 mlo mandylo@charter.net Mandy
155 mlo mandylo@charter.net Mandy
156 garmondino tralaala@optonline.net Gail
156 garmondino tralaala@optonline.net Gail
157 pjimenez polly@musiciansatplay.com Polly
157 pjimenez polly@musiciansatplay.com Polly
158 hheggie haheggie@gmail.com Hazel
158 hheggie haheggie@gmail.com Hazel
159 jduarte jwd@jwduarte.com Jennifer
159 jduarte jwd@jwduarte.com Jennifer


sample table
wp_users:
id /user_login /user_email
2 /Patrice /tazcdn@hotmail.com
wp_usermeta:
user_id /meta_key /meta_value
2 /first_name /Patrice
2 /last_name /Fitzgerald
2 /nickname /pfitzgerald


please help

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-06-23 : 22:46:45
it will be easier for others to help you if you can post some sample data and your query over here.



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-06-23 : 23:56:57
your query that joins the 2 tables produces 1 to many result.

Is there a column user_id in the wp_usermeta table ?

can you also post the structure for these 2 tables ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

leracj
Starting Member

13 Posts

Posted - 2013-06-24 : 00:24:50
I just answered my own post



SELECT DISTINCT

please help
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-24 : 00:31:33
quote:
Originally posted by leracj

having problems with the my sql code
i want it to post only unique ones
my sql code
SELECT ID, user_login, user_email, meta_value
FROM wp_users um, wp_usermeta u
WHERE user_id = ID
AND meta_key = 'first_name'


SELECT DISTINCT ID, user_login, user_email, meta_value
FROM wp_users um, wp_usermeta u
WHERE user_id = ID
AND meta_key = 'first_name'


--
Chandu
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-06-24 : 03:06:53
what is the primary key of the wp_usermeta ?

looks like for every ID, you have 2 record in wp_usermeta with meta_key = 'first_name'

Check your data


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -