Hello,

i have a problem with my query. any body give suggestion please.

i have two tables named as "users" and "userimages"

in the users table there are
1)userid (primary key)
2)name
3)subscription package (Brong or gold)

and in the next table "userimages" fields are
1)auto_id
2)userid (foreign key)
3)image url.

now i want to display users order by "subscription packages" and display whose image urls are not null those user profiles display first.

thanks.

Use this query: -

select u.name, u.subscription_package, i.image_url from users as u LEFT JOIN userimages as i ON u.userid = i.userid where i.image_url != "" order by u.subscription_package

Always make a practise that, don't use space between your field name for e.g. subscription package should be subscription_package.

select u.name, u.subscription_package, i.image_url from users u,userimages i where u.userid =i.userid;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.