Mutiple tables and queries

How do I join something like this together:

$query = ("SELECT * FROM profiles,follow
           WHERE follow.friend ='$user' 
               AND follow.user !='$user' 
               AND profiles.user1 =follow.user 
           ORDER BY id DESC limit 20");

or

("SELECT * FROM profiles WHERE user1='$user'");

I need the query to display two different things how do I do that.

Thanks

Tom.

Answers


Use UNION:

SELECT * 
FROM profiles, follow
WHERE follow.friend ='$user' 
  AND follow.user !='$user' 
  AND profiles.user1 =follow.user 
  ORDER BY id DESC limit 20
UNION
SELECT * 
FROM profiles 
WHERE user1='$user'

try this

$query = "SELECT * FROM profiles,follow WHERE follow.friend ='$user' and follow.user !='$user' and profiles.user1 =follow.user and profiles.user1='$user' order by id DESC limit 20";

This one?

SELECT
    *
FROM
    follows
INNER JOIN
    profiles
    ON (profiles.user1 = follow.user)
WHERE
    follow.friend = '{$user}'
    AND follow.user != '{$user}'
    AND profiles.user1 = '{$user}'
ORDER BY
    profiles.id DESC
LIMIT 20

Need Your Help

warning when using BOOL variable in objective-c

iphone objective-c ios boolean

I am trying to initalize my BOOL variable to YES but its giving me this warning.. not quite sure what to do.. it still seems to be working fine but just wondering how I can get rid of the warning.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.