Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

getting records from 2 tables
I have 2 tables each with a column called 'item'

I want to list all the records from both tables where items like
'%screws%'

Each table currently holds less than 500 trial records
This is the raw SQL I tried which sends the server into an infinate loop
Can anyone tell me the syntax for how I should do this please?

SELECT * FROM table1,table2 WHERE table1.item OR table2.item like
'%screws%'

--------------
tag

Report this thread to moderator Post Follow-up to this message
Old Post
tag
03-10-08 12:20 AM


Re: getting records from 2 tables
tag wrote:
> I have 2 tables each with a column called 'item'
>
> I want to list all the records from both tables where items like
> '%screws%'
>
> Each table currently holds less than 500 trial records
> This is the raw SQL I tried which sends the server into an infinate loop
> Can anyone tell me the syntax for how I should do this please?
>
> SELECT * FROM table1,table2 WHERE table1.item OR table2.item like
> '%screws%'
>
> --------------
> tag
Look at the UNION operator

Report this thread to moderator Post Follow-up to this message
Old Post
Bob Stearns
03-10-08 12:20 AM


Re: getting records from 2 tables
On Sun, 09 Mar 2008 14:41:12 GMT, tag <tag@nospm.co.uk> wrote:

>
>I have 2 tables each with a column called 'item'

Look up LEFT JOIN... ON

<http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.php> explains it
well IMO.
--
Locate your Mobile phone: <http://www.bizorg.co.uk/news.html>
Great gifts: <http://www.ThisBritain.com/ASOS_popup.html>

Report this thread to moderator Post Follow-up to this message
Old Post
David Quinton
03-10-08 01:05 PM


Re: getting records from 2 tables
tag wrote:
> I have 2 tables each with a column called 'item'
>
> I want to list all the records from both tables where items like
> '%screws%'
>
> Each table currently holds less than 500 trial records
> This is the raw SQL I tried which sends the server into an infinate loop
> Can anyone tell me the syntax for how I should do this please?
>
> SELECT * FROM table1,table2 WHERE table1.item OR table2.item like
> '%screws%'
>
> --------------
> tag

Without looking very hard (and I gues a lot), you seem to have two problems:

1) your query might try to deliver 500*500 (250,000) records.

2) You logic is very wrong.

Bad:  WHERE table1.item OR table2.item like'%screws%'
Better: WHERE table1.item like '%screws%' OR table2.item like'%screws%'
(but still wrong)

You still need to look into a proper JOIN



Report this thread to moderator Post Follow-up to this message
Old Post
Preventer of Work
03-14-08 03:08 AM


Re: getting records from 2 tables
On Sun, 09 Mar 2008 14:41:12 GMT, tag wrote...
>
>
>I have 2 tables each with a column called 'item'
>
>I want to list all the records from both tables where items like
>'%screws%'
>
>Each table currently holds less than 500 trial records
>This is the raw SQL I tried which sends the server into an infinate loop
>Can anyone tell me the syntax for how I should do this please?
>
>SELECT * FROM table1,table2 WHERE table1.item OR table2.item like
>'%screws%'
>
>--------------
>tag


A couple of others had already made recommdnations for "UNION" and "LEFT JOI
N".
If there was no relation between table1 and table2, then you need to run the
m as
separate queries.


SELECT * FROM table1 WHERE table1.item like '%screws%';
SELECT * FROM table2 WHERE table2.item like '%screws%';

Tom
--
NewsGuy Free Trial Accounts
Now a massive 20 Gigabytes of unrestricted downloads !
http://newsguy.com/overview.htm


Report this thread to moderator Post Follow-up to this message
Old Post
Tom
03-19-08 12:06 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:05 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.