SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 multiple entry to single entry
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

leracj
Starting Member

Philippines
13 Posts

Posted - 06/28/2013 :  14:47:15  Show Profile  Reply with Quote
MY CODE:
----------------------------
SELECT DISTINCT ID, user_login, user_email, meta_value
FROM wp_users um, wp_usermeta u
WHERE (
user_login LIKE '%tr%'
OR meta_value LIKE '%tr%'
OR user_email LIKE '%tr%'
)
AND (
user_id = ID
AND (
meta_key = 'first_name'
OR meta_key = 'last_name'
OR meta_key = 'city'
OR meta_key = 'address'
OR meta_key = 'programs'
)
)
ORDER BY `um`.`user_login` ASC
LIMIT 0 , 30
-----------------------------------
Output:

table wp_user:


table wp_usermeta:




i want to know how to have only 1 single entry every distinct wp_users id

please help

rs3gold
Starting Member

2 Posts

Posted - 06/28/2013 :  22:55:07  Show Profile  Reply with Quote
unspammed
Go to Top of Page

leracj
Starting Member

Philippines
13 Posts

Posted - 06/29/2013 :  12:06:10  Show Profile  Reply with Quote
I did once again answer my own post...

SELECT DISTINCT ID, user_login, user_email, meta_value, count(*)
FROM wp_users um, wp_usermeta u
WHERE (
user_login LIKE '%tr%'
OR meta_value LIKE '%tr%'
OR user_email LIKE '%tr%'
)
AND (
user_id = ID
AND (
meta_key = 'first_name'
OR meta_key = 'last_name'
OR meta_key = 'last_name'
OR meta_key = 'city'
OR meta_key = 'address'
OR meta_key = 'programs'
)
)
group by ID,user_login,user_email
having count(*) > 1 ORDER BY `um`.`ID` ASC

please help
Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 06/29/2013 :  14:14:07  Show Profile  Reply with Quote
Is this what you want assuming you don't care about met_value:


SELECT DISTINCT ID, user_login, user_email, MAX(meta_value)
FROM wp_users um, wp_usermeta u
WHERE (
user_login LIKE '%tr%'
OR meta_value LIKE '%tr%'
OR user_email LIKE '%tr%'
)
AND (
user_id = ID
AND (
meta_key = 'first_name'
OR meta_key = 'last_name'
OR meta_key = 'last_name'
OR meta_key = 'city'
OR meta_key = 'address'
OR meta_key = 'programs'
)
) 
group by ID,user_login,user_email
 ORDER BY `um`.`ID` ASC

Go to Top of Page

leracj
Starting Member

Philippines
13 Posts

Posted - 06/29/2013 :  14:21:59  Show Profile  Reply with Quote
thanks for the post but i already answered this


quote:
Originally posted by MuMu88

Is this what you want assuming you don't care about met_value:


SELECT DISTINCT ID, user_login, user_email, MAX(meta_value)
FROM wp_users um, wp_usermeta u
WHERE (
user_login LIKE '%tr%'
OR meta_value LIKE '%tr%'
OR user_email LIKE '%tr%'
)
AND (
user_id = ID
AND (
meta_key = 'first_name'
OR meta_key = 'last_name'
OR meta_key = 'last_name'
OR meta_key = 'city'
OR meta_key = 'address'
OR meta_key = 'programs'
)
) 
group by ID,user_login,user_email
 ORDER BY `um`.`ID` ASC



Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 06/29/2013 :  14:51:02  Show Profile  Reply with Quote

You don't have meta_value in your group by clause,
were you able run this query without any errors?

quote:
Originally posted by leracj

I did once again answer my own post...

SELECT DISTINCT ID, user_login, user_email, meta_value, count(*)
FROM wp_users um, wp_usermeta u
WHERE (
user_login LIKE '%tr%'
OR meta_value LIKE '%tr%'
OR user_email LIKE '%tr%'
)
AND (
user_id = ID
AND (
meta_key = 'first_name'
OR meta_key = 'last_name'
OR meta_key = 'last_name'
OR meta_key = 'city'
OR meta_key = 'address'
OR meta_key = 'programs'
)
)
group by ID,user_login,user_email
having count(*) > 1 ORDER BY `um`.`ID` ASC

please help

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/29/2013 :  14:54:25  Show Profile  Reply with Quote
One thing to note
You're using MySQL I guess seeing LIMIT 0 , 30 etc in query. Please keep in mind that this is ms sql server forum and there're not too much expertise on MySQL here. So your best bet would be posting in MySQL forums like www.dbforums.com to get MySQL specific syntax help.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/29/2013 :  14:54:26  Show Profile  Reply with Quote
One thing to note
You're using MySQL I guess seeing LIMIT 0 , 30 etc in query. Please keep in mind that this is ms sql server forum and there're not too much expertise on MySQL here. So your best bet would be posting in MySQL forums like www.dbforums.com to get MySQL specific syntax help.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000