/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Select from 2 tables

I have 2 tables: lss1 & lss2 and the content needs to be selected from either table depending on the criteria.

[code=php]$sql=”SELECT * FROM lss1, lss2 WHERE id=$variable”;[/code]

I am getting the following error: “Couldn’t execute query: Column ‘id’ in where clause is ambiguous”

How do I not make the “id” ambiguous when it could go to either table?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ZABISep 15.2012 — specify id from which table to select. i think you need...

$sql="SELECT * FROM lss1, lss2 WHERE lss1.id=$variable and lss1.id=lss2.id";
Copy linkTweet thisAlerts:
@NogDogSep 15.2012 — If the two tables are truly separate (as opposed to joined on a common field), then you may need to do a union
[code=php]
select col1, col2, col3 from table1 where something='something'
union
select col2, col2, col3 from table2 where something='something'
[/code]

Note that you must select the same number/type of columns from each table.
×

Success!

Help @beylah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...