Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messagetag 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
Post Follow-up to this messageOn 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>
Post Follow-up to this messagetag 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
Post Follow-up to this messageOn 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.