Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,665 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,161 people online right now. Registration is fast and FREE... Join Now!




Query need help

 
Reply to this topicStart new topic

Query need help

angela5
post 15 Jul, 2007 - 01:55 AM
Post #1


New D.I.C Head

*
Joined: 12 Jun, 2007
Posts: 5


My Contributions


Please help just with Mysql query:
Select all users which are in table "listingsdb" and are Not in "userfavoritelistings"...

CODE
$searchSQL = "SELECT distinct(" . "listingsdb.listingsdb_id), " . "listingsdb.userdb_id, " . "listingsdb.listingsdb_title FROM " . "listingsdb, " . "userfavoritelistings " . $string_table_list . " WHERE (listingsdb_active = 'yes') " . $string_where_clause . " AND (" . "userfavoritelistings.listingsdb_id = " . "listingsdb.listingsdb_id) ";
            $searchSQLCount = "SELECT COUNT(distinct(" . "listingsdb.listingsdb_id)) as total_listings FROM " . "listingsdb, " . "userfavoritelistings " . $string_table_list_no_sort . " WHERE (listingsdb_active = 'yes') " . $string_where_clause_nosort . " AND (" . "userfavoritelistings.listingsdb_id = " . "listingsdb.listingsdb_id) ";


This post has been edited by angela5: 15 Jul, 2007 - 02:14 AM
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 15 Jul, 2007 - 11:54 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


What's the schema for each of the tables? Any value that appears in both?
User is online!Profile CardPM

Go to the top of the page

angela5
post 15 Jul, 2007 - 11:18 PM
Post #3


New D.I.C Head

*
Joined: 12 Jun, 2007
Posts: 5


My Contributions


QUOTE(Amadeus @ 15 Jul, 2007 - 12:54 PM) *

What's the schema for each of the tables? Any value that appears in both?


listingsdb - all listings database
userfavoritelistings - contains just listing id which user has added to their favorites, so id value appears here when it added in fav.

I need search listings which are in listingsdb but are not in "userfavoritelistings" (listings that aren't in favorites)
User is offlineProfile CardPM

Go to the top of the page

Trogdor
post 16 Jul, 2007 - 03:11 AM
Post #4


D.I.C Addict

Group Icon
Joined: 6 Oct, 2006
Posts: 517



Thanked 3 times

Dream Kudos: 125
My Contributions


CODE

SELECT * from listingsdb left outer join userfavoritelistings on userfavoritelistings.listingsdbID = listingsdb.id
WHERE  userfavoritelistings.listingsdbID IS NULL

User is offlineProfile CardPM

Go to the top of the page

bernard.assaf
post 16 Jul, 2007 - 10:44 PM
Post #5


New D.I.C Head

Group Icon
Joined: 15 Jul, 2007
Posts: 41



Dream Kudos: 100
My Contributions


what are the attributes in your tables to know which is the common part.
User is offlineProfile CardPM

Go to the top of the page

angela5
post 18 Jul, 2007 - 09:55 AM
Post #6


New D.I.C Head

*
Joined: 12 Jun, 2007
Posts: 5


My Contributions


QUOTE(Trogdor @ 16 Jul, 2007 - 04:11 AM) *

CODE

SELECT * from listingsdb left outer join userfavoritelistings on userfavoritelistings.listingsdbID = listingsdb.id
WHERE  userfavoritelistings.listingsdbID IS NULL


icon_up.gif icon_up.gif icon_up.gif Yes, thank you Trogdor. It works. resolved.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:50AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month